As a Python developer, write a telegram bot based on Python-telegram-bot version 3.17.…
- User
As a Python developer, write a telegram bot based on Python-telegram-bot version 3.17.
The goal is for the support team don't miss any questions from clients and for all questions to get an answer from the support team.
The bot should listen to messages in certain client's group chats that it's already added there and forward unanswered questions to a private telegram channel to inform teammates about unanswered questions. The bot should wait for 1 hour, if any questions from clients hold more than 1 hour, the bot should forward the client message to a private channel.
- The bot should identify the question patterns or if the customer is sharing a file with .zip.enc or .zip or .enc files.
- If the client sends more than one question in several messages, the bot should forward all.
- If the last message in the clients' groups is from one of the support team members, the bot should consider the questions as resolved, and no need to keep track it, until the next questions.
- When the bot is forwarding the client's message to the private telegram channel, it should update the message with the actual client's group name and the waiting time of the client's message.
- support teammates' chat ID is collected in a teammates.json file.
- Assistant
- User
I'll add this bot to the clients' groups, so do I still need GROUP_IDS = ['CLIENT_GROUP_CHAT_ID1', 'CLIENT_GROUP_CHAT_ID2'] if not please modify the code.
- Assistant
If you want the bot to listen to all group chats where it is added, you can remove the
GROUP_IDScheck from the code.Here's the modified version of the
handle_messagesfunction:pythondef handle_messages(update: Update, context: CallbackContext): if update.message.document and update.message.document.file_name.endswith(('.zip.enc', '.zip', '.enc')) or is_question(update.message.text): if update.message.from_user.id not in SUPPORT_TEAM: context.chat_data.setdefault('questions', {}) context.chat_data['questions'][update.message.message_id] = { 'created_at': update.message.date, 'is_resolved': False, } elif update.message.from_user.id in SUPPORT_TEAM: for question_id in context.chat_data.get('questions', {}): context.chat_data['questions'][question_id]['is_resolved'] = True