Search code examples
pythontelegramtelegram-botpy-telegram-bot-api

pyTelegramBotAPI. How to connect a manager to the conversation with a user?


I am trying to create a possibility for a user to call a technical support in the chat with the bot. I need to find a way to connect a real person to chat.

So, for example, user starts the bot and uses a command '/support'. Manager (real person) gets a notification (somehow) and can step in into the conversation in the same chat (where user called a support). Bot meanwhile should stop answering any commands until manager or user stops the help-conversation (with a '/stop' command, for example). How can I create something like that?


Solution

  • You can use a method or algorithm called step, the way you do this is you have to:

    1. Create a database (doesn't have to be online necessarily, you can use sqlite, json, redis and etc...)
    2. For every user and support guy when they enter /start for the first time have to create a row for them containing (user_id integer, step string) the step doesn't matter at the beginning you can set it empty and for user_id set it to the user id based on their telegram message (you can create a is_supporter field to know if a user is supporter or just create another table for them)
    3. When the user for example types /support and someone accepts their support ticket you have to set the user step to something for like "support_{support_id}" where the support_id is the guy who answers question and you do the same thing but for the support guy
    4. Everytime they send a message, before you do anything else (like check for commands and etc...) you have to check their step, if it is like support_x you have to redirect their message to x
    5. When they for example enter the /cancel command you can clear the step field both for supporter and user so they won't message each other anymore