Getting started overview

Getting started with TamTam for developers primarily involves interacting with its Bot API. This API facilitates the creation of automated bots that can send messages, manage chats, handle media, and respond to user interactions. The process generally includes account creation, bot registration, obtaining an API access token, and then making authenticated HTTP requests to the API endpoints.

The TamTam Bot API is a RESTful interface that uses JSON for request and response bodies. It supports various methods for managing messages, users, and chats. Developers can use any programming language capable of making HTTP requests, though official SDKs are available for Python, Java, PHP, Go, and Ruby to simplify interaction.

This guide outlines the essential steps to get a TamTam bot operational and send a first message, focusing on the core authentication and API interaction principles.

Quick Reference Table

Step What to Do Where
1. Create TamTam Account Register for a TamTam user account. TamTam homepage
2. Create a Bot Use the BotFather within TamTam to create a new bot and get its token. TamTam application (search for @BotFather)
3. Understand API Basics Review the Bot API documentation for endpoints and request formats. TamTam Bot API documentation
4. Install SDK (Optional) Install a TamTam SDK for your preferred language. Language-specific package manager (e.g., pip install tamtam-bot-api for Python)
5. Make First Request Send a simple message using your bot token and an API endpoint. Your development environment (e.g., Python script, cURL)

Create an account and get keys

To interact with the TamTam API, you first need a TamTam user account and then a bot with an associated API token. This token acts as the authentication credential for your bot's API calls.

1. Register a TamTam User Account

If you do not already have one, create a TamTam user account. This account will be used to access the TamTam application where you can interact with the BotFather to create your bot.

  • Navigate to the TamTam website or download the TamTam application.
  • Follow the registration process, typically involving a phone number or email address.

2. Create a Bot and Obtain an API Token

TamTam uses a special bot, often referred to as 'BotFather' (similar to Telegram's approach), to manage other bots. You interact with BotFather directly within the TamTam application to create your new bot and receive its unique API token.

  1. Open TamTam and find BotFather:
    • Open the TamTam application (web, desktop, or mobile).
    • Use the search function to find @BotFather.
    • Start a chat with @BotFather.
  2. Start the bot creation process:
    • In the chat with @BotFather, send the command /newbot.
    • @BotFather will prompt you for a name for your bot. This is the human-readable name displayed in chats.
    • Next, @BotFather will ask for a username for your bot. This must be unique and end with 'bot' (e.g., MyAwesomeBot).
  3. Receive your API Token:
    • Upon successful creation, @BotFather will provide you with an HTTP API token. This token is a long string of characters (e.g., a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0).
    • Important: Keep this token secure. It provides full control over your bot. Do not expose it in public repositories or client-side code.

Your first request

Once you have your bot's API token, you can make your first API call. A common first step is to send a simple text message to a chat or channel where your bot is a member. For this example, we will use the sendMessage method.

Prerequisites

  • Your TamTam bot's API token.
  • The ID of a chat or channel where your bot is an administrator or member. You can find a chat ID by forwarding a message from that chat to @BotFather and using the /getchatid command, or by inspecting the URL in the web client (e.g., https://tamtam.chat/chat/CHAT_ID).
  • A tool for making HTTP requests (e.g., curl, Python's requests library, or a similar HTTP client in your preferred language).

Sending a Message with cURL

Using curl is a straightforward way to test API calls directly from your terminal. Replace YOUR_BOT_TOKEN and YOUR_CHAT_ID with your actual values.

curl -X POST \
  "https://api.tamtam.chat/messages?access_token=YOUR_BOT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "chat_id": YOUR_CHAT_ID, "text": "Hello from my TamTam bot!" }'

This command sends a POST request to the /messages endpoint, including your bot's access token as a query parameter. The JSON body specifies the target chat_id and the text of the message.

Sending a Message with Python

If you prefer using a programming language, Python with the requests library is a common choice. First, install the requests library if you haven't already:

pip install requests

Then, create a Python script like the following:

import requests
import json

BOT_TOKEN = 'YOUR_BOT_TOKEN'
CHAT_ID = YOUR_CHAT_ID  # Ensure this is an integer or string depending on its format
MESSAGE_TEXT = 'Hello from my TamTam bot via Python!'

url = f"https://api.tamtam.chat/messages?access_token={BOT_TOKEN}"
headers = {'Content-Type': 'application/json'}
payload = {
    'chat_id': CHAT_ID,
    'text': MESSAGE_TEXT
}

response = requests.post(url, headers=headers, data=json.dumps(payload))

if response.status_code == 200:
    print("Message sent successfully!")
    print(response.json())
else:
    print(f"Failed to send message: {response.status_code}")
    print(response.text)

Replace 'YOUR_BOT_TOKEN' and YOUR_CHAT_ID with your actual bot token and the target chat ID. Running this script will send the specified message to the TamTam chat.

Common next steps

After successfully sending your first message, consider these common next steps to expand your bot's functionality and integrate it more deeply with TamTam:

  1. Set up Webhooks: Instead of polling the API for new updates, set up a webhook to receive real-time notifications when users interact with your bot or send messages. This is generally more efficient and responsive. The TamTam Webhooks documentation details how to configure this.
  2. Explore More API Methods: The TamTam Bot API offers a range of methods for managing messages (e.g., editMessage, deleteMessage), working with chats (e.g., getChat, getChats), handling media, and user interactions. Review the full TamTam Bot API reference to understand available functionalities.
  3. Handle User Input: Implement logic to process incoming messages and commands from users. This involves parsing the message text, identifying commands (e.g., /start, /help), and responding appropriately.
  4. Integrate with External Services: Connect your TamTam bot to other APIs and services to perform tasks such as retrieving data from a database, fetching information from a weather API, or triggering actions in a CRM. For example, a bot could interact with a service like Stripe's API to process payments or Cloudflare's API for DNS management, though direct payment processing would require careful security considerations.
  5. Use Official SDKs: While direct HTTP requests are feasible, using one of the official TamTam SDKs (Python, Java, PHP, Go, Ruby) can simplify development by providing pre-built methods and handling serialization/deserialization.
  6. Error Handling and Logging: Implement robust error handling for API calls and log relevant information to diagnose issues and monitor your bot's performance.

Troubleshooting the first call

If your first API call to TamTam does not work as expected, consider the following common issues and troubleshooting steps:

  1. Incorrect API Token:
    • Issue: The most frequent problem is an invalid or expired API token.
    • Solution: Double-check that you copied the token correctly from BotFather. Ensure there are no extra spaces or characters. If in doubt, you can ask BotFather for your bot's token again using the /token command followed by your bot's username.
  2. Invalid Chat ID:
    • Issue: The chat_id specified in your request might be incorrect or the bot may not have access to that chat.
    • Solution: Verify the chat_id. Ensure your bot has been added to the target chat or channel. For channels, the bot often needs to be an administrator to send messages.
  3. Incorrect Endpoint or HTTP Method:
    • Issue: Using the wrong URL for the API endpoint or the wrong HTTP method (e.g., GET instead of POST).
    • Solution: Refer to the TamTam Bot API documentation to confirm the correct endpoint URL and required HTTP method for the sendMessage method. It should be a POST request to https://api.tamtam.chat/messages.
  4. Malformed JSON Payload:
    • Issue: Errors in the JSON body of your request, such as missing commas, incorrect syntax, or incorrect field names.
    • Solution: Use a JSON linter or validator to check your payload. Ensure all required fields (chat_id, text) are present and correctly formatted.
  5. Network or Firewall Issues:
    • Issue: Your local network environment or firewall might be blocking outgoing HTTP requests to the TamTam API.
    • Solution: Test connectivity using a simple ping api.tamtam.chat or try making the request from a different network environment.
  6. API Rate Limits:
    • Issue: If you are sending many requests in a short period, you might hit TamTam's API rate limits.
    • Solution: Check the API response for rate limit headers (if provided) or error messages indicating rate limiting. Implement exponential backoff or ensure your bot respects rate limits.
  7. Error Responses:
    • Issue: The API returns an error status code (e.g., 400, 401, 403, 500) with an error message.
    • Solution: Always inspect the HTTP status code and the response body for detailed error messages. These messages often provide specific clues about what went wrong. For example, a 401 Unauthorized typically points to an invalid token, while a 400 Bad Request often indicates an issue with the request parameters or body.