Back to Blog
Integration Guides

How to Integrate Twilio with Telegram: Step-by-Step Guide

Wire Twilio into Telegram to forward SMS notifications to Telegram channels and build bots that bridge SMS and Telegram conversations.

DA
Danial A
Senior Twilio Consultant, Telphi Consulting
June 22, 2026
7 min read
Twilio
Integration
Messaging
AI Bots
How to Integrate Twilio with Telegram: Step-by-Step Guide

Twilio and Telegram integrate through a middleware bridge that connects the Twilio Messages API webhook and the Telegram Bot API, enabling bidirectional message relay between SMS and Telegram channels so teams using Telegram for internal communication can receive and reply to customer SMS messages without leaving Telegram. This integration is used by operations teams, support centers, and developer communities that coordinate internally via Telegram and want to handle inbound customer SMS from within their existing Telegram workspace rather than switching to a separate SMS interface. The connection involves creating a Telegram bot via BotFather, registering the bot webhook to your middleware, and configuring your Twilio number's inbound SMS webhook to the same middleware, which routes messages between the two platforms in both directions.

What You Need Before You Start

Create a Telegram bot by messaging BotFather at t.me/BotFather in Telegram, sending the /newbot command, entering a display name and a username ending in bot, and receiving the bot token in the format 123456789:ABCdefGHIjklMNOpqrSTUvwxYZ that you store securely as an environment variable in your middleware. Retrieve your Telegram chat ID by adding your bot to the target Telegram group or channel, sending a test message, and calling GET https://api.telegram.org/bot{botToken}/getUpdates to retrieve the update payload, then reading the message.chat.id field which is a negative integer for groups and a positive integer for private chats. Configure your Twilio phone number's inbound SMS webhook by navigating to the Twilio Console under Phone Numbers, then Active Numbers, clicking your number, scrolling to the Messaging section, and setting the A Message Comes In webhook URL to your middleware endpoint URL with the HTTP method set to HTTP POST. Identify the E.164 phone number of the Telegram bot's responding agent if you want bidirectional SMS replies, or store a mapping of Telegram user IDs to phone numbers if multiple agents reply via Telegram and each reply should come from a different Twilio number.

Step-by-Step Integration Guide

Register the Telegram bot webhook by calling GET https://api.telegram.org/bot{botToken}/setWebhook?url={yourMiddlewareUrl}/telegram-webhook so Telegram delivers all messages sent to the bot to your middleware endpoint, then verify the registration by calling GET https://api.telegram.org/bot{botToken}/getWebhookInfo and confirming the url field matches your middleware URL. In your middleware's Twilio inbound SMS handler, receive the POST from Twilio containing the From phone number and Body text, then forward the message to your Telegram group or channel by calling POST https://api.telegram.org/bot{botToken}/sendMessage with a JSON body containing chat_id set to your stored Telegram chat ID and text set to a formatted string combining the SMS sender's phone and the message body, such as SMS from +12125551234: Hello, I need help with my order. In your middleware's Telegram webhook handler, receive the POST from Telegram containing the message text, chat ID, and the Telegram sender's first name, extract the original SMS sender's phone from the stored message relay record keyed by the Telegram chat ID and message thread, and dispatch a Twilio reply SMS by calling POST https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Messages.json with the To set to the original SMS sender's phone and the Body set to the Telegram agent's reply text. Store each inbound SMS relay in your database with the SMS From phone, the Twilio To number, the Telegram chat ID, and the Telegram message ID of the forwarded message so your middleware can look up the original SMS context when a Telegram reply arrives and route the reply back to the correct SMS sender.

Common Issues and How to Fix Them

Telegram groups have multiple members who may all reply to the forwarded SMS message in the group, causing your middleware to receive multiple Telegram webhook events for the same inbound SMS and dispatching multiple Twilio reply SMS to the customer from different group members simultaneously. Implement a message locking mechanism that marks an inbound SMS as claimed when the first Telegram group member replies, ignoring subsequent Telegram replies to the same forwarded message thread by checking the database for an existing claim on that SMS message ID before dispatching the Twilio reply. The Telegram Bot API does not support sending messages to channels where the bot is not an admin with the Post Messages permission, causing the bot.sendMessage call to fail with a 403 Bad Request response when the bot was added as a regular member rather than an admin. Add the bot as an admin to your Telegram channel or group by opening the channel settings, navigating to Administrators, clicking Add Administrator, and selecting your bot, granting it at minimum the Post Messages permission. Twilio inbound SMS webhook requests must receive an HTTP 200 response within 10 seconds to be considered delivered, but forwarding the message to Telegram and waiting for the Telegram API response can sometimes exceed this timeout when the Telegram API is slow. Return HTTP 200 to Twilio immediately when the inbound SMS arrives and forward the message to Telegram asynchronously in a queued background task to prevent Twilio from treating the delivery as failed and retrying the webhook.

How to Get More from This Integration

Build a Twilio alert-to-Telegram notification system that sends SMS from customers directly to a Telegram operations channel as structured messages with the customer's name, phone, and inquiry category formatted using Telegram's HTML parse mode so urgent messages are highlighted in bold and non-urgent messages appear as plain text, enabling your operations team to triage inbound SMS without leaving their Telegram workflow. Add a Twilio Verify OTP relay through Telegram by dispatching the OTP as a Telegram message to an internal security channel rather than SMS for internal staff authentication, keeping the OTP off the public phone network entirely and delivering it through the encrypted Telegram channel for higher security in administrative authentication flows. Create a bidirectional Twilio SMS bridge for Telegram communities by assigning each community member a virtual Twilio long code number, so external SMS messages sent to their virtual number arrive as Telegram DMs via the bot, and their Telegram replies are forwarded as SMS from the virtual number, giving community members an SMS-reachable identity without sharing their personal phone numbers. Extend the integration to Telegram channels for broadcast SMS with reply tracking by forwarding a single outbound SMS campaign draft to a Telegram approval channel, waiting for an admin to react with a checkmark emoji, and triggering the Twilio bulk SMS dispatch from that Telegram reaction event, building an approval-gated broadcast workflow inside Telegram.

Conclusion

Twilio and Telegram together create a powerful bidirectional bridge between customer SMS and your team's Telegram workspace, eliminating the need for a dedicated SMS interface while keeping all customer communication in one place. Get in touch with Telphi Consulting to build and deploy the Twilio Telegram middleware bridge for your team's specific workflow.

Share this article:
0 views

Ready to Transform Your Business Communications?

Get a free consultation with our VoIP experts and discover how we can help you save costs, improve efficiency, and scale your business.

Comments (0)

Join the discussion and share your thoughts (AI-moderated for quality)

Protected by AI moderation

Be the first to comment

No comments yet. Share your thoughts below.