Today’s post will cover the ability to preserve conversations when sending notifications. The typical scenario we are trying to avoid is: a user is answering a series of troubleshooting questions, and then receives a stock alert. The alert proposes to see more details, and the user can’t go back to finish his troubleshooting steps.
To avoid such disturbance, the BuddyScript engine runs notification and initiate alerts in different conversations from the one used to answer regular queries.
Each conversation is uniquely identified by an identifier. A system variable tells you what your conversation id is:
SYS.Conversation
Another system variable tells you the id of the conversation used to answer queries. This is called the user conversation.
SYS.User.Conversation
If those two values are the same, you are in the user conversation, otherwise, don’t bother initiating a dialog.
You can switch the user conversation to be the conversation you are in with the following statement:
set user conversation
You can also switch the user conversation to be a conversation you specify by doing:
set user conversation CONVERSATION_ID
With this statement, you can temporarily highjack the user conversation and later restore it.
Finally, you can forward a query you just received to any conversation with the following statement:
forward query CONVERSATION_ID
With those three elements, you can highjack the user conversation, receive the user queries, forward the queries that you don’t care to the previous user conversation, and restore the previous user conversation.
To illustrate this, here is the “Say Hi to my friend” example with the ability for the friend to reply back.
// Respond to Hi
declare procedure DisplayGreeting(FRIEND_NAME, GREETING)
? Say Hi to my friend EMAIL=AnEMailAddress
RESULT = initiate EMAIL, "MSN": DisplayGreeting(SYS.User.NickName, "Hi") {createprofile=false loadprofile=true}
- Ok, done.
procedure DisplayGreeting(FRIEND_NAME, GREETING)
- Hey, your friend FRIEND_NAME says GREETING!
SOURCE = SYS.ConversationSource
if SYS.Conversation = SYS.User.Conversation
// This is the user conversation
- Do you want to say GREETING back to FRIEND_NAME ?
? Yes
RESULT = initiate SOURCE.ScreenName, SOURCE.Service: DisplayGreeting(SYS.User.NickName, GREETING + " back")
- Done.
? No
- Fine.
else
SAVED_USER_CONV = SYS.User.Conversation
set user conversation
- If you want to say GREETING back to your friend, just say "reply"
? reply
RESULT = initiate SOURCE.ScreenName, SOURCE.Service: DisplayGreeting(SYS.User.NickName, GREETING + " back")
- Done.
? ANYTHING=AnythingRaw
forward query SAVED_USER_CONV
set user conversation SAVED_USER_CONV
The first thing DisplayGreeting does is to save SYS.ConversationSource in a variable. This variable contains some information on the user the initiate comes from, and will be used to initiate back.
It then identifies if the current conversation is the user conversation. That would be the case if the user was not in session with the agent. Depending on the result, we will phrase our question differently. The response will have to be less ambiguous if the user was already in a conversation with the agent.
If this is the user conversation, the rest of the code is simple.
If it is not the user conversation, the procedure highjacks it. If the user sends “reply”, an initiate is sent back to the originator. If the user sends anything else, the query is forwarded to the previous user conversation. In any case, the user conversation is restored to the previous one.
You can try this example with a routine with a dialog and see if the user that receives the greeting can ignore the question and respond to the dialog he was in. You can also test if he can still respond to his dialog after saying “reply”.
Here now is the kitchen timer example with a snooze capability. The same logic is used here.
// Kitchen Timer with snooze
declare procedure Ring()
variable KITCHEN_TIMER_NOTIFICATION = ""
? Kitchen timer
- Ok, I'm setting up the time, how many minutes do you want ?
? DELAY=Integer
- Alright, I will notify you in DELAY minutes
KITCHEN_TIMER_NOTIFICATION = notify in DELAY minutes: Ring()
? Cancel Kitchen timer
if KITCHEN_TIMER_NOTIFICATION = ""
- What timer ?
else
cancel notify KITCHEN_TIMER_NOTIFICATION
KITCHEN_TIMER_NOTIFICATION = ""
- Done.
procedure Ring()
- DRRRRRRRING !!!!!
Your time is up!
KITCHEN_TIMER_NOTIFICATION = ""
if SYS.Conversation = SYS.User.Conversation
// This is the user conversation
- Do you want to snooze ?
? Yes
KITCHEN_TIMER_NOTIFICATION = notify in 5 minutes: Ring()
- Will ring again in 5 minutes.
? No
- Fine.
else
SAVED_USER_CONV = SYS.User.Conversation
set user conversation
- To give an extra 5 minutes, type "snooze"
? Snooze
KITCHEN_TIMER_NOTIFICATION = notify in 5 minutes: Ring()
- Will ring again in 5 minutes.
? =AnythingRaw
forward query SAVED_USER_CONV
set user conversation SAVED_USER_CONV
Next post will explain how to empower your scripts by combining initiate and notify with dialogs. This is done through actions.
Damien.