Hello fellow agent developers,
I am going to present, in this post and the next 3 ones, the notion of conversations in BuddyScript and the way to best use them with the “initiate” and “notify” functionalities.
Here are the items I am going to cover in those four posts:
1. Basic use of initiate and notify.
2. Controlling the execution of initiate and notify.
3. Handling conversation ids.
4. Using actions.
Controlling the execution tells you how to know if a user is talking to the agent or not, if he has ever talked to the agent or not, and how to cancel a notification.
Handling conversation ids will show you how to interact with the user from a notification without disturbing the current conversation he was in. For example, the user plays a game with the agent and the agent throws a stock ticker alert, proposing the user to see details; the user should be able to finish his game.
Using actions will show you how to exchange information between users back and forth in an efficient manner, and how to combine notifications with dialogs. An example of use is a trivia game with a timer.
But today, I’m going to describe the initiate and notify functionalities.
Initiate is a BuddyScript functionality that lets you call a procedure on behalf of someone else. This procedure is executed with the profile of the user you specified, and any output generated will be sent to that user.
The first example is the “Say Hi to my friend” program.
// Say Hi to my friend
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!
In this example, user Joe will ask to say Hi to Mary, providing Mary’s live messenger screen name. As a result, Mary will receive a greeting from the agent. In this example, Mary has to have talked to the agent already; she must already have a profile stored.
The notify functionality calls a given procedure at a given time from the same user. It is used to create timers and reminders.
An example for it is the “Kitchen Timer”.
// Kitchen timer
declare procedure Ring()
? 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
ID = notify in DELAY minutes: Ring()
procedure Ring()
- DRRRRRRRING !!!!!
Your time is up!
Perfect to boil an egg.
If you want the best of both worlds, being able to specify the procedure to call, the time to execute it and for which user, you can combine the two.
Here’s the “Friend’s reminder” example
// Friend's reminder
declare procedure RemindFriend(FRIEND_NAME, ACTION, TIME)
declare procedure RemindNotification(ACTION)
? Remind my friend EMAIL=AnEMailAddress to ACTION=AnythingRaw at TIME=ATime
RESULT = initiate EMAIL, "MSN": RemindFriend(SYS.User.NickName, ACTION, TIME)
- Ok, that's done.
procedure RemindFriend(FRIEND_NAME, ACTION, TIME)
STIME = TIME.hour + ":" + TIME.minute
- Hey, SYS.User.ScreenName, FRIEND_NAME would like to remind you to ACTION at STIME.
ID = notify day at STIME: RemindNotification(ACTION)
procedure RemindNotification(ACTION)
- Hey there, it's time to ACTION!
The procedure “RemindFriend” doesn’t need to output anything to work. The alternative would be to do the notify first, followed by initiate.
Tomorrow, we’ll see in more details those two functionalities.
Damien.