Conversation tracking is the way I plan to implement a proper support for keyboards (as a layer above those) and forced replies.
@bot.command("support")defsupport_command(conversation, chat, message, args):
"""Ask for support"""conversation.start("support")
chat.send("Hey, what's your problem?", attach=conversation)
@bot.conversation("support")defbug_report_conversation(conversation, chat, message):
# First step is asking the user which problem he hasif"problem"notinconversation.data:
conversation.data["problem"] =message.textchat.send("OK! To which email address do you wish being contacted?",
attach=conversation)
else:
problem=conversation.data["problem"]
email=message.textmydb.add_ticket(problem, email)
chat.send("Thank you for contacting our support!")
conversation.end()Let's break this down:
- The
/support command starts the support conversation: from this moment and until you close the conversation (or it times out) every message which is detected as part of the conversation will be routed to the relative function - The conversation is attached (the equivalent of the current
extra argument) to the message you send to the user, and this acts as a Telegram ForceReply - Every message the user sends now is routed to the conversation function, so you can interact with your user more easily
- Conversations have a dedicated shared memory, unique for every conversation, so you can store any information the user sent to you (it will be deleted after you end the conversation)
- After you did what you want with the user, you can
.end() the conversation.
I think conversations will aid you creating even more awesome bots, but if you have any idea please share it here!
Conversation tracking is the way I plan to implement a proper support for keyboards (as a layer above those) and forced replies.
Let's break this down:
/supportcommand starts thesupportconversation: from this moment and until you close the conversation (or it times out) every message which is detected as part of the conversation will be routed to the relative functionextraargument) to the message you send to the user, and this acts as a Telegram ForceReply.end()the conversation.I think conversations will aid you creating even more awesome bots, but if you have any idea please share it here!