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. 👇
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:
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. 🙌
Let’s imagine you’ve got an SMS subscriber who you want to move over to Telegram. Here’s how to do it:
Let’s break this down step-by-step. 👇
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:
urn_parts()
function to extract the phone number from the SMS contact’s URN.+12065551212
. Telegram is picky 😬 about embedding the plus character, so next we'll trim that off since we don't actually need it anyway.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))
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:
/start phone12065551212
.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!
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.
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! 🎉
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!
Got any questions or need help along the way? Don’t hesitate to reach out—we’re here for you! 🤗