Skip to content

Add support for tracking conversations #53

@pietroalbini

Description

@pietroalbini

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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions