Sign In
Bringing Your SMS Contacts Over to Telegram
📱➡️💬 Save on Costs and Improve Engagement!

If you're using TextIt to manage your bot across multiple channels, you already know how easy it is to connect with users via SMS and chat apps like Telegram at the same time. But did you know you can save on messaging fees by encouraging your SMS subscribers to make the switch to Telegram? 😎

In this post, we’ll walk you through how to invite your SMS contacts to use your Telegram bot, while keeping all their history in your database—so no data is lost in the process! Let’s dive in. 👇

Save on Costs and Improve Engagement by Seamlessly Migrating SMS Subscribers to Telegram


How SMS and Telegram Work Together 🤝

TextIt supports multi-channel communication, which means you can have different "addresses" (or URNs) for the same contact on different channels. Think of it like this:

  • If someone reaches out to you by SMS, their contact is linked to their phone number.
  • If they reach out on Telegram, their contact is linked to their Telegram ID.

Now, if someone uses both channels, you'll have two different entries for the same person: one for SMS and one for Telegram. Our goal is to merge these contacts into a single profile while preserving their full history. 🙌


🛠️ Steps to Bring Your SMS Contacts Over to Telegram

Let’s imagine you’ve got an SMS subscriber who you want to move over to Telegram. Here’s how to do it:

  1. Send a Text to Your SMS Contact with a link to your Telegram bot.
  2. They Click the Link, which starts a Telegram session.
  3. Your SMS Subscriber Gets a Confirmation Request, asking them to confirm they want to switch to Telegram.
  4. They Confirm by Typing “Yes”, and you add their new Telegram ID to their contact.

Let’s break this down step-by-step. 👇


📲 Step 1: Sending the Invite

To get your SMS contact over to Telegram, you'll need to send them a link to your Telegram bot.

You can grab your bot’s link by opening the bot in Telegram and clicking the "Share" button. Our message might look something like this:

Save on messaging fees by switching to our Telegram bot. Just click here: https://t.me/PurringtonBot?start=phone@(text_slice((urn_parts(contact.urn).path), 1))

But hold on, how do we encode the SMS phone number into this link? You can do this using TextIt’s magic expressions! ✨

Here's how:

  • We use the urn_parts() function to extract the phone number from the SMS contact’s URN.
  • This would return something like, +12065551212. Telegram is picky 😬 about embedding the plus character, so next we'll trim that off since we don't actually need it anyway.
  • To do that, we'll put that inside of a text_slice function to trim off the first character.

@(text_slice((urn_parts(contact.urn).path), 1))

So the Telegram link will look like this:

https://t.me/PurringtonBot?start=phone@(text_slice((urn_parts(contact.urn).path), 1))


📩 Step 2: Responding to the Invite

When your contact clicks the link, it will trigger a special flow in your Telegram bot.

You’ll want to check if the user is joining through their own link or using the invite link. This can be done by checking if the link starts with /start phone (which includes their phone number).

Here’s how we handle that:

  • If the user clicks the invite link, it will pass the phone number in the format /start phone12065551212.
  • We use our little friend text_slice() again to pull out the phone number, so we can match it to the contact in our database.

@(text_slice, input, 12)

The end result will just be the phone number (without the ➕), or from our previous example, 12065551212. Then we just use the Start Somebody Else action to start that phone number in our confirmation flow!


✅ Step 3: Adding the New Telegram ID

When you're linking a contact’s phone number to their Telegram ID, it’s important to confirm everything before proceeding. First, we’ll simply ask: “Are you sure you want to switch to Telegram for this contact?” 🤔 If they say "Yes", we know it's safe to move forward and link their phone number to their Telegram ID.


This confirmation step is crucial because, without it, someone could start the Telegram bot with a random phone number, potentially hijacking a contact that doesn’t belong to them. 😱 So, confirming the switch first helps us avoid mix-ups and keeps everything secure.


Once we get the green light 🚦, the next step is figuring out their Telegram ID.

Since the contact started the process via Telegram, we can use the @parent.contact reference to grab their URN, which is a unique identifier. The URN looks something like this:

telegram:1234567#norbertk


Here, 1234567 is the actual Telegram ID, and #norbertk is an extra identifier, like a username or tag. 📱💡 We can easily access this number by using the @parent.contact.urn expression, which pulls the correct Telegram ID for linking.


By confirming the phone number and using the @parent.contact.urn to grab the correct Telegram ID, we ensure that the right person is linked to their Telegram account, keeping everything safe and secure. 🔐 Whether you choose the phone number method or opt for a random code, the goal is always to ensure smooth, secure linking. 💪✨

When working with the parent contact's URN, we can break it down into parts to extract the specific details we need. For example, if we pass the parent contact’s URN through urn_parts, we can access the path—which, in the case of Telegram, is the user’s unique number.


To get this number, we can use:

@(urn_parts(parent.contact.urn).path) 📱

Now, we could stop right here, but there's an extra bonus! Telegram users can also have an optional display name (like a username or custom tag), which is often added after the # symbol. If we want to include that, we can grab it too with:

@(urn_parts(parent.contact.urn).display) 🏷️

So, putting it all together, we get this slightly more complex expression🔗:

@(urn_parts(parent.contact.urn).path)#@(urn_parts(parent.contact.urn).display)

It may look a bit like magic ✨, but it's really just two separate expressions, with the # in the middle to tie them together! This gives us the full Telegram ID, including both the user number and the display name, if available.

And just like that, you’ve added their Telegram contact to the database! 🎉


✨ And That’s It! 🎉

By following these steps, you’ll be able to seamlessly bring your SMS subscribers over to Telegram, saving on messaging fees and keeping all your data in one place. 📊 Plus, you won’t lose any contact history!


Check out this YouTube tutorial that will walk you through the process: YouTube Tutorial

Got any questions or need help along the way? Don’t hesitate to reach out—we’re here for you! 🤗