Tutorial: Forward SMS to Telegram

From the everyday life of our customers: Use the Telegram chatbot to receive text messages

The beauty of working with an SMS gateway is that you can benefit from SMS as a strong medium, while the gateway’s capabilities give you a lot of flexibility. Especially the function to forward SMS is very popular with our customers to realize many creative application scenarios. For example, one of our customers had the following request: He wanted to forward SMS to Telegram.

The idea – Forward SMS to Telegram

Our customer receives SMS via a dedicated inbound number. Both the text of the incoming SMS and the sender need to be forwarded to the chatbot. Here’s the thing: Making the settings to forward incoming SMS is easy in our webapp, but the addition that both text and sender are forwarded requires additional parameters.

The implementation

To put this idea into action, we need three components: The chatbot, a chat ID, and the actual redirection for incoming SMS. We create the chatbot in Telegram, after which we can determine the chat ID. We then set the forwarding in the seven webapp. If you already have a chatbot and know the chat ID, you can skip to The forwarding section.
Let’s get started! You’ll be able to forward SMS to Telegram in no time.

The chatbot

First, let’s create a Telegrambot. For this you will need:

Open the Messenger and log in if necessary. Then search for @BotFather in the contacts search bar and select the BotFather. Notice that the correct bot has a blue check mark. Then click Start in the chat.

In this chat you can manage your bots and create new bots. We want to create a new bot and send the /newbot command to do so. You will be prompted to choose a name for your bot. This name will be displayed in the conversation. After that, you choose a username for your bot. This one must end in “bot”.

Wählen Sie den richtigen Bot aus. Sie erkennen ihn an dem blauen Haken.

Be careful, only the top bot is the right one!

That’s it! You have created your Telegram bot. In the confirmation message you will receive the link to the conversation with your new bot and your token, which will become important for us in the next section.

The Chat ID

Now we are missing the chat ID to successfully set up the forwarding. There are a few ways to find out this ID, but we recommend this one: Open the chat with your new bot and click “Start”. Send a message to the bot. Then call https://api.telegram.org/botTOKEN/getUpdates. Instead of TOKEN, of course, you put the token for your bot that you received from BotFather. In your return, you will see the chat id. It is after the value "id", not after "update_id".

        "text":"Hello again"

In one of our test runs, we had to send our bot a second message to get an output other than {"ok":true, "result":}. Perhaps a little more patience would have done the trick though! In all other cases, the output worked immediately after sending the first message.

The forwarding

Now we want your new chatbot to show you incoming SMS with their sender. To do this, log in to our webapp and go to the Developers menu item. On the right side you will find your webhooks. We want to create a new webhook for our chatbot function and click on the green plus sign.

You can set SMS forwarding via webhook in the developer area
In the Webhook settings, configure the forwarding of the SMS to Telegram

Paste this URL: https://api.telegram.org/botMYTOKEN/sendMessage?chat_id=MYCHATID&text=SMS+from+{{sender}}:+{text}} Instead of MYTOKEN use the token you received earlier, instead of MYCHATID put the determined chat ID. Under Event you select SMS_MO. Under Filter you can set whether you want to forward all incoming SMS or only those sent to a specific number. Make your selection and save.

And that’s it! You are now able to forward SMS to Telegram.

Do you also have an example of how you use our products? Do you have ideas that you have not yet been able to implement?
We’d love to hear your story!

Best regards
Your sms77 team

Header: iStock.com/tdhster

19 Comments. Leave new

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

This site uses Akismet to reduce spam. Learn how your comment data is processed.