Is it possible to somehow put a password on a bot in Telegram? And it turns out that it can be controlled by anyone who knows his login.
- fourYou can ask a question to the user and if he answers the question incorrectly, then stop the conversation - VenZell
- @VenZell, thanks! Now I will write) And how to make your comment the answer to this question? - Fiveteen
- @VenZell, Another such question, do not prompt a team that breaks the connection with the bot? - Fiveteen
- If I knew exactly how to do this, I would have written the answer. That this can be done I know for sure. - VenZell
- @VenZell, Thanks again! I will look for. If I find, I will answer the question. - Fiveteen
|
2 answers
The task is solved by ignoring messages from the user with a certain chat_id . To do this, you need to store them all and set the lock flag where necessary. Storing chat_id is also useful for many other tasks.
Example ( pseudocode ):
while (true) { var updates = GetUpdates(); foreach update in updates { var chat_id = update.chat.id; if chat_id in (%list_of_blocked_users%) then continue; //else do something with update ... } } - So how can I know the user's chat_id in advance? After all, it is better and easier to make just access for "your", knowing their chat_id. I forgot to indicate in the question that I am writing in Python. But in principle, I understand your idea. I came up with the following: 1) When the bot receives the / start command, it says hello and says "Enter password to continue" 2) I think you can assign a password to some variable, for example - "passwd = 12345" to the next def function, otherwise make a return. Attempts to write this code continue ... - Fiveteen
- 2By the way, there is such a thing as Deep linking . Perhaps this will be the most optimal solution - Anatol
- How do you know your "own" chat_id? From there, recognize others as well. With a password, the idea is basically working, but some kind of not elegant, to put it mildly. Invent the bicycle. You do not need to know in advance, you need to write down all the chat_id and flag those that are spamming / trying to break the bot / misuse / etc.
- so add the / password command and add chat_id to the white list - eri
|
users = [123, ..., ..., n] # chat id # Органичение доступа к боту по ID @bot.message_handler(func=lambda message: message.chat.id not in users) def some(message): bot.send_message(message.chat.id, 'Извините, Создатели не разрешают мне общаться с незнакомыми пользователями) Well, suddenly it is useful
users_start = [123, 456, -100] # последнее - id группы если бот что-то должен делать в группе # Органичение выполнение команды start @bot.message_handler(func=lambda message: message.chat.id not in users_start, commands=['start']) def some(message): bot.send_message(message.chat.id, 'У Вас нет прав на выполнение данной команды') |