Telegram bot to wait for user reply

梦想与她 提交于 2019-12-06 04:52:04
anatol

You should use ForceReply markup with your requests and check replies from user - when reply contains Username in reply_to_message field of the received Message then you should send a request for password etc.


Example (pseudocode):

// Asking user for username/password
Bot.SendChatAction(update.Message.Chat.Id, ChatAction.Typing);
Bot.SendTextMessage(update.Message.Chat.Id, "Type your username, please");

// Checking incoming messages for replies
if (update.Message.ReplyToMessage.Text.Contains("your username"))
{
    if (!IsValidUsername(update.Message.ReplyToMessage.Text)) return;
    SaveUsernameToDb(update.Message.Chat.Id, update.Message.ReplyToMessage.Text);
    Bot.SendChatAction(update.Message.Chat.Id, ChatAction.Typing);
    Bot.SendTextMessage(update.Message.Chat.Id, "Username has been successfully saved!");
}
else
{
    ...
}

By the way, asking for private data such as username/password in plain-text-chat is quiet unsafe and very bad practice.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!