At a glance
Capabilities
The capability matrix for every platform is on Supported platforms.
Connect a bot
A Telegram bot connects in one request: you send its token, and SocialAPI returns the connected account.1
Create the bot
Open Telegram and message @BotFather. Send
/newbot, choose a display name, then choose a username that ends in bot.2
Copy the token
BotFather replies with a token of the form
123456789:ABCdefGhIjKlMnOpQrStUvWxYz-1234. Anyone who holds the token controls the bot, so keep it secret.3
Connect the bot
Send the token as Response (HTTP 201):
metadata.bot_token:username is the bot’s username and display_name is its name. Without brand_id in the request, SocialAPI creates a brand for the bot. SocialAPI also sends account.connected to your webhook endpoints.
A missing bot_token returns 400 validation.field_required. A token Telegram rejects returns 401 platform.telegram.auth.
One bot, one receiver
Connecting the bot points its Telegram webhook at SocialAPI and replaces any webhook the bot already had. Telegram delivers a bot’s updates to one receiver only: while the bot is connected to SocialAPI, another service cannot receive its messages by webhook or withgetUpdates.
Disconnecting the account (DELETE /v1/accounts/{account_id}) removes the webhook, so Telegram stops sending the bot’s messages to SocialAPI. The token itself stays valid until you revoke it with /revoke in @BotFather. A bot token has no expiry date; after a revoke, connect the bot again with the new token.
Receive messages
Each message a person sends to your bot arrives as adm.received event and is stored in the inbox. Telegram offers no message history to bots, so the inbox holds only messages received after you connected the bot.
The dm.received data carries the fields you need to reply and to match the stored message:
Photos, documents, voice notes, audio, videos, video notes, animations, and stickers all arrive in
content.media. The url is a SocialAPI URL of the form https://api.social-api.ai/v1/inbox/media/{id}: Telegram files can be downloaded only with the bot’s token, so SocialAPI keeps a copy for you. Fetch the URL with your API key. The same URL appears as attachment_url on the stored message, and it stays available for 30 days. Telegram does not let bots download files larger than 20 MB, so the URL of such a file returns 410. Fetch an inbound attachment lists every status this URL returns.
Edited and deleted messages raise no event. The full event payload is on Webhook events.
Send messages
You reply withPOST /v1/inbox/conversations/{conversation_id}/messages, the same endpoint as every other platform. The request fields are on Direct messages.
account_id returns 400 validation.field_required.
These rules are specific to Telegram:
- The person writes first. Telegram does not let a bot start a conversation. Until the person sends
/startor any message to the bot, a send fails with403 telegram.cannot_message. The same code is returned when the person blocked the bot. Once the person has written, there is no reply window: the bot can answer at any time. - Photo or document. SocialAPI sends a file whose name ends in
.jpg,.jpeg,.png,.gif, or.webpas a photo, and any other file as a document. Thetypefield of the attachment does not change this choice. - Captions. An attachment’s
captionis shown under the file. The messagetextis always a separate message, also with the single-file shorthandattachment_url. - Interactive content is not sent. Telegram messages carry no
buttons,quick_replies,cards, orlist_sections. SocialAPI sends thetextand ignores those fields.reply_to_message_idandmessage_tagare ignored as well. - No
platform_attachment_id. Send files asurlormedia_idattachments.
Limits
Telegram enforces the text, caption, and file limits. A request over one of them, or a file URL Telegram cannot fetch, fails with
400 validation.telegram_bad_request, whose message carries Telegram’s own description. When Telegram rate-limits the bot, the send fails with 429 platform.telegram.rate_limit: wait the number of seconds in the Retry-After header before you retry.
Scopes
A Telegram bot has no OAuth scopes. The bot token gives full control of the bot, and SocialAPI uses it to receive the bot’s messages and to send replies. The account supports themessages.read and messages.write permissions, which SocialAPI alone enforces.
Related
- Direct messages: the request fields for sending DMs and attachments
- Webhook events: the full
dm.receivedpayload - Connect accounts: brands, reconnecting, and disconnecting
- Errors: every Telegram error code
- Supported platforms: what each platform supports