Skill template: Basic Dialogue Starter template


#1

Objective

This template is intended to give developers a quick entry point into building a skill which creates a simple dialogue between Jibo and the user. It works on the principle of a back-and-forth conversation: you say something, Jibo reacts, you say something else, Jibo reacts, etc…, until the conversation ends.

This template can be used to put together almost any kind of skill that requires back-and-forth interaction. It uses the basic behaviors available within the SDK and can be modified quickly to fit your needs.

It also comes with a few built-in cool things:

  • Open-ended setup so you can expand it to allow Jibo to react to one or many different “commands”.
  • Gives you access to the speakers name, if available, in a global variable called notepad.currentSpeaker.
  • Supports a continuos dialogue loop managed by a single global variable called notepad.listenForHeyJibo.
  • Uses an on-board NedB database to store if this is the user’s first access to your skill and saves that in a global variable notepad.newUser (available only after “Hey Jibo”).
  • Gives you access to store additional user preferences in that same NedB database.
  • Provides the basic structure of your rule file (in main.rule) with most of the standard syntax pre-set so that you can modify it to suit your needs. The main.rule file uses an easy to understand rule -> action setup to quickly tie in to your skill.

How to use this template

To get started immediately, just jump down to the installation instructions at the end of this post. To learn more about how to customize it for your own skill, keep reading.

To customize this skill template, you’ll need to understand it’s structure.

###Template Structure
The template begins with Jibo in idle mode listening for “Hey Jibo”. When he hears that, he looks at the speaker (closest entity), records the current speaker’s name, if available, in notepad.currentSpeaker and creates a database to store the user’s in-skill preferences if the user is new.

Above: The basic flow of the dialogue starter
skill template, starting with “Hey Jibo”.

Then he waits attentively for a “command” from the user - basically anything that matches a rule in the main.rule file - and responds with the corresponding action that the rule file returns. For example, if Jibo hears “Say hi”, the rule file returns the action sayHello and the skill runs the sayHello action via a simple switch/case setup.

After completing the action, Jibo continues listening for additional “commands”, or returns to an idle state, depending on whether the global variable notepad.listenForHeyJibo is true (idle) or false (keep listening).

To add your own command, just add a new rule to the main.rule file. If other rules already exist (and they will if this is your first modification to the main.rule file), be sure to add a separator “|” character before your new rule and encapsulate your rule in parentheses. Be sure to send back an action response when your new rule is called by adding the action return variable. For example, let’s add a new rule called “spin around” which returns the action spinAround to the default main.rule file:

TopRule = $* (
   # Add your rules and responses here
   ( (say $hello){action='sayHello'} ) |
   ( ($play (*a) $sound{sound=sound._item}){action='playSound'} ) |
   ( (say $goodbye){action='endDialogue'} ) |
   ( (spin around){action='spinAround'} )
) $*;

Now, in our behavior tree, we simply need to create a new branch to our Switch statement to run our new spinAround action. Right-click the Switch behavior on Line 9 and add a child Sequence. Inside this sequence, you can put any actions you want Jibo to take when a user tells him to “spin around” (e.g. a PlayAnimation behavior linking to an animation of Jibo spinning). Right-click the new Sequence you just added and choose Add Decorator, then choose Case. In the conditional under Decorator Arguments, add this code:

() => {
  let results = notepad.results;
  if(results!==undefined && results.action!==undefined){
    if(results.action=="spinAround"){ return true; }
  }
  return false;
}

Be sure to change the reference to spinAround in the above code to match the new action you setup in your main.rule file. Finally, add a new ExecuteScript behavior as the last item in your new Sequence with this code:

() => {
  notepad.listenForHeyJibo = false;
}

Change the false to true if you want Jibo to return to an idle state after the action completes.

That’s all there is to adding a new action to this setup. Feel free to change the existing actions in the starter skill template (playSound, sayHello, and endDialogue) as well to whatever you like or remove them completely.

Installation

  1. Download the following 2 files added to begin your skill with this template:
    main.bt (19.4 KB) (copy to the “behaviors” folder and overwrite the current file)
    main.rule (689 Bytes) (copy to the “rules” folder)

  2. Add the NedB Node package to your skill via the command line. Just navigate to your skill’s folder and use npm install nedb.
    NOTE: If you do not want to use user preference storage or NedB, you can skip this step. Just make sure to remove the included database code from the ExecuteScript behavior on Line 2 and the Listen behavior on Line 8.

Future Releases

I plan on updating this template as soon as the Jibo team releases their embedded way of saving user preferences in your skills. In the meantime, this template uses NedB to do the same.

I also would highly value your feedback, whether it’s about the skill itself or the documentation. Just hoping I can help make skill building an easier process for everyone.


#2

Thank you!

I’m a total newb but following these instructions I was not only able to get your template running, but also add a new rule and get it to work. (with a little trial and error)

Regards,
Tony


#3

I ran your skill for a first time @michael and it works well here. Did you install the NedB npm also @codemonkey2k5 ? Otherwise the skill won’t run correctly.


#4

It all worked for me with a little trial and error. I must have been distracted when I wrote my initial post. Re-read it and then edited it so that it actually makes sense. :wink:

Regards,
Tony


How-to: Connect Jibo to IBM's Watson for visual recognition and language sentiment
#5

@michael This is so AWESOME! Thank you so much for sharing.