I’m building a bot that has to receive a group as an input from a user, so that it knows what group the user wants to do some X action. How to do that?
I thought about deep linking with some callback data just like poll-bot does, but the thing is that I do not want the user to write anything on the group (yes, both the user and the bot are in the group).
I also thought about feeding a database with all the users from a group (where the bot is), and then ask the user which group he wants, but there is still no way to do that with telegram bot API.
Thanks!
2
Answers
Every group chat as well as single chat has a chat_id. It won’t change as long as the chat exists. To learn the chat_id you can use a bot like this one. It will always answer with the chat id of the chat in which he received a message:
To do some X action you can use this chat_id. It won’t change, so you just can store them as a variable in your script.
If you want to let the user choose in what group he wants to do some X action, you first need to know all groups the user is a member in. As far as I know there is no way to receive this information with telegram. It makes sense, otherwise the bot owner could know all the users groups. I doubt this is what any user wants.
In my view the best way is to let the user specify the group ID.
Maybe you could allow to create an alias for a chat_id, like “news-chat” or something that is easy to remember.
You could use deep link to ask the user to add your bot to the group; when the user chooses a group, you link that group’s chat_id to the user’s chat_id on yout database;
Next time your user wants to perform a task, you just show all the linked groups.