Hybrid Bot in MAX: AI Consultant and Expert Proxy in One Chat
In the MAX messenger, a system has been implemented where a single bot combines the functions of an AI assistant and a mediator between clients and experts. For routine questions, the bot independently provides instructions from the FAQ. When escalation is needed, it discreetly passes the message to a specialist using the reply function. The patient stays in one chat, unaware of the mode switching.
The system solves two problems: repetitive requests burden experts, and direct client contact with them breaks isolation. The bot filters 90% of inquiries, routing the rest through text markers and chat_id.
Architecture of Two Modes
The bot operates based on the sender's chat_id and message content.
AI Consultant Mode:
- Recognizes standard requests (appointment booking, cancellation).
- Provides ready-made instructions from the loaded FAQ.
- Resolves most inquiries without human intervention.
Proxy Mode:
- When a request for a doctor is made, it asks for the message text.
- Appends it with the marker
Client chat ID: {chat_id}. - Sends it to the expert via an internal function.
Experts reply using the "reply" button, the bot parses the marker and forwards the response to the client's chat with the signature Consultant: {ID}.
Technical Implementation of Routing
The key mechanism is using reply in MAX to link responses.
- Message Marking: Each client message to an expert receives an invisible suffix with chat_id. Example:
Please tell the doctor that the test results are ready
Client chat ID: 482910
- Reply Processing: The bot checks incoming messages for the presence of a marker in reply_to. If the sender's chat_id is in the expert whitelist—it extracts the ID and sends the response to the client.
- Role Identification: A simple list of expert chat_ids. All others are clients.
##ROLE_START##
Your name is Alice. You assist client communication for "MedConsult."
In each response, add guiding inline buttons for the user. To add buttons, append this command to your response:
Buttons in a row:
##INLINE:Button1;Button2##
Buttons stacked:
##INLINE:[Button1][Button2]##
You have a list of consultants:
ID: 15, chat_id: 246XXXXXXXX
If a client wants to send a message to a consultant, request the consultant ID and message text, then send the message using function #554.
To use function 554, use the bot token: `{{VOP_BOT_MAX_TOKEN}}`. Do not use the `reply_to_message_id` parameter when sending messages via function 554. In the `message` parameter when sending via function 554, always append to the user's message text: `\n\nClient chat ID: {{chat_id}}`, here take `chat_id` from the timestamp in the `chat_id` parameter present in every client message (do not use `user_id`, specifically `chat_id`)—this is important because without this parameter, the consultant cannot reply to the client.
If you see in the client's message label: `reply to` and the message being replied to contains the phrase: `Client chat ID`, then use exactly this client chat ID as `user_chat_id` (not from the timestamp), and as `message` use the literal reply text with the addition `\n\nConsultant: {{ID}}` (here take the ID by matching the chat_id from the timestamp with the consultant list) and run function 554 without follow-up questions. This will enable consultants to answer client questions.
Keep responses brief.
##ROLE_END##
This prompt integrates the logic into the AI model, minimizing custom code.
User Perspective Scenarios
- Routine: Request for instructions—instant response from the bot.
- Escalation: Message to a doctor—pause, then a signed response in the same chat.
- Mix: Switching between modes without notifications or new chats.
The user sees a continuous dialogue; the bot masks the complexity.
Advantages for Developers:
- No state databases.
- Minimal routing: two rules + marker.
- Scalable to multiple experts via chat_id list.
Implementation Checklist
To replicate:
- Messenger with reply API (MAX, Telegram).
- Whitelist of expert chat_ids.
- Prompt with marking and parsing rules.
- Message sending function with bot token.
- FAQ for AI responses.
The system doesn't require complex infrastructure, relying on built-in platform capabilities.
Key Points
- Seamless Switching: Client stays in one chat, roles change silently.
- Routing via Reply: Text marker + "reply" button ensure precise delivery.
- Filtering by chat_id: Simple client/expert dichotomy without overhead.
- 90% Automation: AI handles routine, experts handle complex cases.
- Minimal Stack: Prompt + messenger API, no database.
— Editorial Team
No comments yet.