python-botogram/botogram

Add support for tracking conversations

pietroalbini opened this issue · 3 comments

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")
def support_command(conversation, chat, message, args):
    """Ask for support"""
    conversation.start("support")
    chat.send("Hey, what's your problem?", attach=conversation)

@bot.conversation("support")
def bug_report_conversation(conversation, chat, message):
    # First step is asking the user which problem he has
    if "problem" not in conversation.data:
        conversation.data["problem"] = message.text
        chat.send("OK! To which email address do you wish being contacted?",
                  attach=conversation)
    else:
        problem = conversation.data["problem"]
        email = message.text
        mydb.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!

I like this! I am excited to see this and keyboards in 0.3 target!

I'll probably redesign this API, I want to support multiple conversation steps from botogram.

dev72 commented

Hi Pietro, is there currently a way to track conversations in botogram 0.4?