I'm trying to open Telegram from my app, for the users to talk with a bot I made. So far, it is working but the only way I found to get the bot chat opened was using the https://telegram.me/MyBot url. But this way, it opens Safari, and then the user is asked if he wants to open it on the Telegram app. Initially it was asking one time, and then, after the first time, it was just passing thru safari and opening Telegram automatically. But it stopped and now, every single time it loads Safari and some times, it even doesn't shows the popup asking the user if it can open the Telegram app.
Is there any way to use that 'tg://' url (that should open directly the Telegram app) to open a chat with a bot? Only saw working examples with phone numbers. Tried in different ways but no success at all...
Any help would be great.
Thanks in advance!
Our apps are open source and support reproducible builds. This means that anyone can independently verify that our code on GitHub is the exact same code that was used to build the apps you download from App Store or Google Play.
- [Instructor] A Telegram Bot works by sending messages between your server and Telegram's. The system is secure because the two share a secret code known as a Bot Token. You get this token by interacting with a special Telegram user known rather amusingly as The BotFather.
Swift 3/4/5+
This is exactly what you looking for:
let botURL = URL.init(string: "tg://resolve?domain=MyBot")
if UIApplication.shared.canOpenURL(botURL!) {
UIApplication.shared.openURL(botURL!)
} else {
// Telegram is not installed.
}
Don't forget to add URI schema's of Telegram to info.plist:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>tg</string>
</array>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With