Reputation:
I'm developing a Telegram bot, which should be accessible only by its owner (only the owner would be able to add it to groups or see it in the search). Is it possible to achieve this via Telegram services (like BotFather) or should I check in my code if the one who's sending messages to the bot is the owner?
Upvotes: 46
Views: 84745
Reputation: 20820
There's another option described in the telegram docs.
You can use a deeplink to get a unique key from the link and secure your bot. Denying access in your code to anyone who does not have the key.
From the docs:
$memcache_key = "vCH1vGWJxfSeofSAs0K5PA"
$memcache_key
into Memcache for 3600 seconds (one hour)telegram_chat_id
for the user 123. Remove the key from Memcache.telegram_chat_id
. If yes, use the sendMessage
method in the Bot API to send them a message in Telegram.Upvotes: 10
Reputation: 71
I started working a few weeks ago on telegram's bots. For that I've read in the specifications there is no way to create a private bot from botfather. The only way is using a custom command like /password to send a password to the bot and then keep the chat id of the client (when password is correct of course ...). Your bot need to accept commands only from memorized/autentificated chat id as you would do it in a classical way for any other application.
Upvotes: 7
Reputation: 7321
You can check for the chat id (9 digit number) in your code.
For example, if you use this wrapper to create bot, you can use update.message.chat_id
to get chat id. You can also check for the first name (update.message.from_user.first_name
) and last name (update.message.from_user.last_name
).
Upvotes: 9
Reputation: 590
There is nothing you can do with BotFather. the only way is to check it inside your code.
Upvotes: 15
Reputation: 7985
You can do this in setting, you need to check by yourself, just exit program if .message.from.id
not equal to yours.
You can disable join group via /setjoingroup
, but you can't invite bot to group either.
Upvotes: 38