| Profil de Windows Live Ag...Windows Live AgentsPhotosBlogListes | Aide |
|
2 juin Scripting tips: conversations 4/4 Using actionsGreetings,
We often design dialogs in BuddyScript to answer to user queries in a specific context. We will see today how by using actions, we can have initiate and notify to answer dialogs, and what can be the use. A dialog is a set of dialog entries that leaves in your script. A dialog entry is some matching information and a script block associated with. The matching information part usually contains patterns, but can contain actions. An action has a name and potentially parameters. The first example is a trivia with timer. // Trivia with timer
? Play trivia - Let's play trivia in what year was the Eiffel Tower built ? in 1889 {action=Right()} in 1943 {action=Wrong()} in 2001 {action=Wrong()} You have 30 seconds to answer NID = notify in 30 seconds: action TimeOut() ? 1889 action Right() - That is correct! ? 1943 ? 2001 action Wrong() - Nope, the correct answer is 1889. action TimeOut() - Too late, the correct answer is 1889.
At first, you can see a common use of actions, and that is with an enumeration. Typing 1 will trigger the action Right, typing 2 or 3 will trigger the action Wrong. Or you can fully type the date and match one of the three patterns. Then, you will notice the action in the notify. After 30 seconds, the notification will answer the dialog for you. If you do respond before the notification triggers, it would be wise to cancel the notification, but if you don’t, that’s ok because when the notification will trigger, no dialog with a TimeOut action will be active and the notification will simply be ignored. Initiates can also use actions, but through the respond statement. The syntax is: RID = respond SOURCE: action MyAction(PARAMS) The SOURCE is an object that contains the user identity (screenname, service and UID), the buddy id and the conversation id to send the action to. Most of the time, you are coming from an initiate and you simply pass the object from SYS.ConversationSource. Don’t forget to save that object in a variable if you have a dialog, because this variable won’t survive the dialog. A typical use for this statement is to get information from another user’s profile. In the following example, I have altered the “Do you know my friend” example to display a friendly name that the friend may have provided. // Do you know my friend(oh you mean Jacky ?)
stored variable PREFERRED_NAME = ""
? Call me NAME=AnythingRaw PREFERRED_NAME = NAME - Ok, for now on, I will call you PREFERRED_NAME
procedure GetPreferredName() if PREFERRED_NAME = "" NAME = SYS.User.ScreenName else NAME = PREFERRED_NAME CID = respond SYS.ConversationSource: action SetName(NAME)
? Do you know EMAIL=AnEMailAddress ? RESULT_NOLOAD = initiate EMAIL, "MSN": GetPreferredName() {createprofile=false loadprofile=false} if RESULT_NOLOAD.Delivered IN_SESSION = true else IN_SESSION = false RESULT_LOAD = initiate EMAIL, "MSN": GetPreferredName() {createprofile=false loadprofile=true} if !RESULT_LOAD.Delivered - Sorry, I can't say that I do exit action SetName(NAME) if NAME != EMAIL - Oh, you mean NAME ? \c - Yes, I know that guy\c if IN_SESSION - , and he/she's talking to me right now. else - .
This script calls GetPreferredName under the friend’s profile, this procedure will respond by sending the preferred name. The script will wait in a dialog to get that answer.
You can also constantly exchange information back and forth between users with respond. You just need one initiate to initiate the dialog. Here is another example that lets two users chat through the agent. // Chatter
declare procedure InviteToChat(NAME) declare procedure Chat(SRC)
? I want to chat with EMAIL=AnEMailAddress - Ok, let me invite your friend over CID = initiate EMAIL, "MSN": InviteToChat(SYS.User.NickName) {createprofile=false loadprofile=true} action Accept() - Ok, your friend has accepted, you may chat now. call Chat(SYS.ConversationSource) action Reject() - Sorry, your friend has declined the offer. action NoResponse() - Hmm, nobody replied...
procedure InviteToChat(NAME) - Hey, your friend NAME would like to chat with you, do you want to accept ? set user conversation SRC = SYS.ConversationSource NID = notify in 30 seconds: action TimeOut() ? Yes - Great, let's start chatting... RID = respond SRC: action Accept() call Chat(SRC) ? No - Fine. RID = respond SRC: action Reject() action TimeOut() - Hmm, you must not be here... RID = respond SRC: action NoResponse() insist: Please, say Yes or No.
procedure Chat(SRC) - Type "quit" to quit the chat. ? TEXT=AnythingRaw RID = respond SRC: action SendText(TEXT) restart dialog action SendText(TEXT) - TEXT restart dialog ? Quit RID = respond SRC: action Quit() - You have terminated the conversation action Quit() - Your friend has terminated the conversation
Have fun with all that.
damien Commentaires (23)Pour ajouter un commentaire, connectez-vous avec votre identifiant Windows Live ID (si vous utilisez Messenger ou Xbox LIVE, vous avez un identifiant Windows Live ID). Connectez-vous Vous n'avez pas d'identifiant Windows Live ID ? Inscrivez-vous
RétroliensL'URL de rétrolien de ce billet est : http://windowsliveagents.spaces.live.com/blog/cns!5BCD45E519E07634!597.trak Blogs Web qui font référence à ce billet
|
|
|