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
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 emptyYes
No
No steps
teamMemberIds 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 senderIdYes
senderId, 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.No
No steps
humanChatId is chatIdIf humanChatId is chatIdYes
No
No steps
customerMessage to blank.Set customerMessage to blank.messageErrorIf a step below fails, save the error as messageErrorTry
incomingMessage.text and save it as customerMessage.Trim incomingMessage.text and save it as customerMessage.On error
customerMessage starts with Support assistantIf customerMessage starts with Support assistantYes
No
No steps
customerMessage starts with Needs a personIf customerMessage starts with Needs a personYes
No
No steps
customerMessage is emptyIf customerMessage is emptyYes
No
No steps
askedBy to a customer in this chat.Set askedBy to a customer in this chat.senderErrorIf a step below fails, save the error as senderErrorTry
incomingMessage.from_username and save it as senderName.Trim incomingMessage.from_username and save it as senderName.senderName isn't emptyIf senderName isn't emptyYes
askedBy to @@senderName.Change askedBy to @@senderName.No
No steps
On error
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 modelCallErrorTry
supportPrompt. Save it as modelResult.Ask OpenAI: supportPrompt. Save it as modelResult.On error
modelReachable to false.Change modelReachable to false.modelText to blank.Set modelText to blank.modelReachable is yesIf modelReachable is yesYes
modelReadErrorIf a step below fails, save the error as modelReadErrorTry
modelResult.response_text and save it as modelText.Trim modelResult.response_text and save it as modelText.On error
modelText to blank.Change modelText to blank.No
No steps
verdictWord to blank.Set verdictWord to blank.draftReply to blank.Set draftReply to blank.modelText isn't emptyIf modelText isn't emptyYes
modelText 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.No
No steps
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 yesYes
handoverReason 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 emptyYes
verdictWord is answerIf verdictWord is answerYes
handoverReason 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 emptyYes
handToAPerson to false.Change handToAPerson to false.No
No steps
Else if @verdictWord is "escalate"
handoverReason to The assistant judged this one to need a person..Change handoverReason to The assistant judged this one to need a person..Otherwise
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..No
No steps
No
No steps
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 noYes
draftReply 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 claimYes
handToAPerson 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..No
No steps
No
No steps
handToAPerson is yesIf handToAPerson is yesYes
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..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 0Yes
reachThem 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.Else if @askedBy starts with "@"
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.Otherwise
No steps
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 emptyYes
handoverExtra to Change handoverExtra to
The assistant's note (not sent to the customer):
draftReply truncated to 800 characters using ... as the ellipsis
.No
No steps
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 handoverErrorTry
humanChatId.Send a message to chat humanChatId.handoverNote truncated to 3800 characters using "..." as the ellipsishandedOver to true.Change handedOver to true.On error
handoverProblem to handoverError.message.Change handoverProblem to handoverError.message.handedOver is noIf handedOver is noYes
customerTold 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 fallbackErrorTry
chatId.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.On error
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.No
No steps
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.holdingReplyNo
answerReply 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