Answers support messages in Telegram from your own material, and hands anything it cannot answer to a person instead of guessing.
Uses
OpenAI
Telegram
Telegram support bot that hands over to a person
Whenever a customer writes to your Telegram support bot, they get an immediate reply. The AI answers from the support material you give it. For anything else, the person who takes handovers is sent the message first, and only once that has gone through is the customer told that someone from your business will get back to them.
Handing over is the rule, not the exception. Refunds, billing, cancellations, complaints, anything about safety or personal data, and anything your material does not cover all go to a person, as does a reply that arrives empty, in the wrong shape or not at all. A handover notifies someone; it closes nothing. The holding reply says plainly that nothing has been changed, and a draft that claims an account was fixed, refunded or closed is handed over instead of sent. If the handover cannot be delivered, the customer is asked to try again later rather than told someone has it, and the run is marked as failed. Messages from your own team are left alone.
You need Telegram (your bot) and OpenAI connected, your answers and policies written down, the chat ID of whoever takes handovers (they must open your bot and press Start once), and your team's Telegram user IDs.
incomingMessage.When a new message is received. Save it as incomingMessage.businessName to blank.Set businessName to blank.supportKnowledge to blank.Set supportKnowledge to blank.humanChatId to blank.Set humanChatId to blank.teamMemberIds to blank.Set teamMemberIds to blank.chatId to incomingMessage.chat_id.Set chatId to incomingMessage.chat_id.chatId is emptyIf chatId is emptyteamMemberIds by , and save it as teamMembers.Split teamMemberIds by , and save it as teamMembers.senderId to incomingMessage.from_user_id.Set senderId to incomingMessage.from_user_id.teamMembers contains senderIdIf teamMembers contains senderIdsenderId, listed in 'teamMemberIds'), so the assistant left it alone.Finish the run: That message came from someone on your team (Telegram user ID senderId, listed in 'teamMemberIds'), so the assistant left it alone.humanChatId is chatIdIf humanChatId is chatIdcustomerMessage to blank.Set customerMessage to blank.messageErrorIf a step below fails, save the error as messageErrorincomingMessage.text and save it as customerMessage.Trim incomingMessage.text and save it as customerMessage.customerMessage starts with Support assistantIf customerMessage starts with Support assistantcustomerMessage starts with Needs a personIf customerMessage starts with Needs a personcustomerMessage is emptyIf customerMessage is emptyaskedBy to a customer in this chat.Set askedBy to a customer in this chat.senderErrorIf a step below fails, save the error as senderErrorincomingMessage.from_username and save it as senderName.Trim incomingMessage.from_username and save it as senderName.senderName isn't emptyIf senderName isn't emptyaskedBy to @@senderName.Change askedBy to @@senderName.askedBy to a customer in this chat.Change askedBy to a customer in this chat.promptRole to You are the first-line support assistant for businessName, replying in a Telegram chat.Set promptRole to You are the first-line support assistant for businessName, replying in a Telegram chat.promptKnowledge to This is the only material you may answer from:Set promptKnowledge to This is the only material you may answer from:
supportKnowledge truncated to 6000 characters using ... as the ellipsis
.promptFormat to Answer in this exact format.Set promptFormat to Answer in this exact format.
First line: the single word ANSWER or the single word ESCALATE, nothing else.
Every line after that: the message to send to the customer.promptWhenAnswer to Use ANSWER only when the material above fully answers what they asked, and the reply needs nothing done to their account.Set promptWhenAnswer to Use ANSWER only when the material above fully answers what they asked, and the reply needs nothing done to their account.promptWhenEscalate to Use ESCALATE for everything else, including: anything the material above does not cover; refunds, billing, cancellations or any change to an account; a complaint, or a message that sounds upset; anything about safety, legal matters or personal data; and anything you are unsure about. When you escalate, write a short note for the colleague picking it up instead of a reply to the customer.Set promptWhenEscalate to Use ESCALATE for everything else, including: anything the material above does not cover; refunds, billing, cancellations or any change to an account; a complaint, or a message that sounds upset; anything about safety, legal matters or personal data; and anything you are unsure about. When you escalate, write a short note for the colleague picking it up instead of a reply to the customer.promptHonesty to You cannot do anything to anyone's account. Never say that you have fixed, resolved, refunded, cancelled, changed or closed anything, and never say a problem is now sorted. Say only what is true: what the material says, or that a person will pick it up.Set promptHonesty to You cannot do anything to anyone's account. Never say that you have fixed, resolved, refunded, cancelled, changed or closed anything, and never say a problem is now sorted. Say only what is true: what the material says, or that a person will pick it up.supportPrompt to promptRole@promptKnowledge@promptFormat@promptWhenAnswer@promptWhenEscalate@promptHonestyMessage from askedBy:Set supportPrompt to promptRole@promptKnowledge@promptFormat@promptWhenAnswer@promptWhenEscalate@promptHonestyMessage from askedBy:
customerMessage truncated to 3000 characters using ... as the ellipsis
.modelResult to nothing.Set modelResult to nothing.modelReachable to true.Set modelReachable to true.modelCallErrorIf a step below fails, save the error as modelCallErrorsupportPrompt. Save it as modelResult.Ask OpenAI: supportPrompt. Save it as modelResult.modelReachable to false.Change modelReachable to false.modelText to blank.Set modelText to blank.modelReachable is yesIf modelReachable is yesmodelReadErrorIf a step below fails, save the error as modelReadErrormodelResult.response_text and save it as modelText.Trim modelResult.response_text and save it as modelText.modelText to blank.Change modelText to blank.verdictWord to blank.Set verdictWord to blank.draftReply to blank.Set draftReply to blank.modelText isn't emptyIf modelText isn't emptymodelText by a new line and save it as modelLines.Split modelText by a new line and save it as modelLines.modelLines in lowercase with : replaced by with . replaced by and save it as verdictWord.Trim the first item of modelLines in lowercase with : replaced by with . replaced by and save it as verdictWord.modelLines joined by a new line and save it as draftReply.Trim the items from index 1 onward of modelLines joined by a new line and save it as draftReply.handToAPerson to true.Set handToAPerson to true.handoverReason to The assistant could not be reached, so the message was passed on rather than left unanswered..Set handoverReason to The assistant could not be reached, so the message was passed on rather than left unanswered..modelReachable is yesIf modelReachable is yeshandoverReason to The assistant did not answer at all, so the message was passed on rather than guessed at..Change handoverReason to The assistant did not answer at all, so the message was passed on rather than guessed at..modelText isn't emptyIf modelText isn't emptyverdictWord is answerIf verdictWord is answerhandoverReason to The assistant said it could answer but wrote no reply, so it was passed on..Change handoverReason to The assistant said it could answer but wrote no reply, so it was passed on..draftReply isn't emptyIf draftReply isn't emptyhandToAPerson to false.Change handToAPerson to false.handoverReason to The assistant judged this one to need a person..Change handoverReason to The assistant judged this one to need a person..handoverReason to The assistant did not answer in the expected form, so it was passed on rather than guessed at..Change handoverReason to The assistant did not answer in the expected form, so it was passed on rather than guessed at..i have fixed, i've fixed, i have resolved, i've resolved, now resolved, i have refunded, i've refunded, i have issued a refund, i have cancelled, i've cancelled, i have canceled, i have updated your account, i have changed your account, i have processed, your ticket is closed, marked as resolved, this is sorted] and save it as resolutionClaims.Create a list of [i have fixed, i've fixed, i have resolved, i've resolved, now resolved, i have refunded, i've refunded, i have issued a refund, i have cancelled, i've cancelled, i have canceled, i have updated your account, i have changed your account, i have processed, your ticket is closed, marked as resolved, this is sorted] and save it as resolutionClaims.handToAPerson is noIf handToAPerson is nodraftReply lowercase and save it as draftLower.Make draftReply lowercase and save it as draftLower.claim in resolutionClaims:For each claim in resolutionClaims:draftLower contains claim If draftLower contains claimhandToAPerson to true.Change handToAPerson to true.handoverReason to The assistant's draft claimed something had been done to the customer's account, which it cannot do, so the draft was not sent..Change handoverReason to The assistant's draft claimed something had been done to the customer's account, which it cannot do, so the draft was not sent..handToAPerson is yesIf handToAPerson is yesreachThem to They have no Telegram username, so you cannot message them directly. They have been asked to reply here with another way to reach them, and that reply will come to you too..Set reachThem to They have no Telegram username, so you cannot message them directly. They have been asked to reply here with another way to reach them, and that reply will come to you too..contactAsk to If there is a better way to reach you, such as an email address, reply here with it..Set contactAsk to If there is a better way to reach you, such as an email address, reply here with it..chatId is less than 0If chatId is less than 0reachThem to Reply to them in the support group..Change reachThem to Reply to them in the support group..contactAsk to blank.Change contactAsk to blank.Message them on Telegram: @askedBy and save it as reachThem.Build the text Message them on Telegram: @askedBy and save it as reachThem.contactAsk to blank.Change contactAsk to blank.Needs a person A support message is waiting for you. From: @askedBy Chat ID: @chatId How to reach them: @reachThem and save it as handoverHead.Build the text Needs a person A support message is waiting for you. From: @askedBy Chat ID: @chatId How to reach them: @reachThem and save it as handoverHead.handoverBody to What they said:Set handoverBody to What they said:
customerMessage truncated to 1500 characters using ... as the ellipsis
Why it came to you:
handoverReason
.handoverExtra to blank.Set handoverExtra to blank.draftReply isn't emptyIf draftReply isn't emptyhandoverExtra to Change handoverExtra to
The assistant's note (not sent to the customer):
draftReply truncated to 800 characters using ... as the ellipsis
.handoverNote to handoverHead plus handoverBody plus handoverExtra.Set handoverNote to handoverHead plus handoverBody plus handoverExtra.handedOver to false.Set handedOver to false.handoverProblem to blank.Set handoverProblem to blank.handoverErrorIf a step below fails, save the error as handoverErrorhumanChatId.Send a message to chat humanChatId.handoverNote truncated to 3800 characters using "..." as the ellipsishandedOver to true.Change handedOver to true.handoverProblem to handoverError.message.Change handoverProblem to handoverError.message.handedOver is noIf handedOver is nocustomerTold to They were asked to try again a little later..Set customerTold to They were asked to try again a little later..fallbackErrorIf a step below fails, save the error as fallbackErrorchatId.Send a message to chat chatId.Support assistant
Thanks for writing in. I have not been able to answer this one myself, and I could not reach the businessName team just now, so please try again a little later.
Nothing has been changed on your account.They could not be sent a reply either (@fallbackError.message). and save it as customerTold.Build the text They could not be sent a reply either (@fallbackError.message). and save it as customerTold.handoverProblem), so nobody has been told about it. Check that 'humanChatId' is right and that the person taking handovers has opened your bot in Telegram and pressed Start. The customer (askedBy, chat ID chatId) wrote: customerMessageStop and report a problem: Could not pass a support message on to the 'humanChatId' chat (handoverProblem), so nobody has been told about it. Check that 'humanChatId' is right and that the person taking handovers has opened your bot in Telegram and pressed Start. The customer (askedBy, chat ID chatId) wrote: customerMessage
customerTold.Support assistant Thanks for writing in. I have not been able to answer this one myself, so I have passed it to the @businessName team and someone will get bac... and save it as holdingReply.Build the text Support assistant Thanks for writing in. I have not been able to answer this one myself, so I have passed it to the @businessName team and someone will get bac... and save it as holdingReply.chatId.Send a message to chat chatId.holdingReplyanswerReply to Support assistantSet answerReply to Support assistant
draftReply truncated to 3200 characters using ... as the ellipsis (keeping words whole)
If that did not answer it, reply here and a person will pick it up.chatId.Send a message to chat chatId.answerReply