All Tutorials / Jlucben / Synbot Plugin Tutorial - interface to Syn Bot Software

Synbot Plugin Tutorial - interface to Syn Bot Software

Step 4 : Manage the dialog with the Bot

Starting a Bot session

A bot session can be started :

by clicking the Start Bot Button on the plugin Main Window
Bot session is started with the userid input in the userid field or with the default userid set in the plugin configuration form if the userid field is empty.

In EZ Scripts :

Code:

Botstart("userid")

where userid is the userid for the bot session
If userid is not entered Botstart() - the default userid set in the plugin configuration form will be used

Or for use in Blockly

Code:

$Botuser= "userid"
ControlCommand("Synbot plugin", Start)


Once the Bot started , you have access to :
. Input Query Text Field with the Send Button in order to enter and send a text query to the bot.
. Stop Button in order to stop the session with the bot
. Save Context Button in order to save the session Context for the userid - see next in step 5

User-inserted image

Console is displaying user messages sent to the Bot and responses received from the Bot
User name linked to the session userid and Bot Name are used for display message prefixing.
Here "Jean Luc" for User Name and "Maya" for Bot name

You can change Bot name in setting Synbot BOT variable Name to the value you wanted.
And so for User Name in setting Synbot USER variable Name to the value you wanted.
(See later in Step 5 for working with Synbot variables)

The EZ Builder variable $Botstarted is set to 0 when there's no bot session started and to 1 when bot session is started.

Querying the Bot with a text message

Once a bot session is started , you can query the Bot with text messages.
This text messages will be analysed by the Bot Engine depending on the SIML files of the Project and a message Bot response will be returned.

There are several ways to query the Bot :

. Enter the query message in the plugin Query Text Field and press Send Button or Return Key
. In EZ Builder scripts :

Code:

Botquery("query message") 

Or

Code:

$botusermessage= "query message"
ControlCommand("Synbot plugin", Query)


Bot response message is splitted in 2 parts :

. A text message which can be (depending on plugin configuration options) speaked or not and sent to PC or EZB speakers ( EZB Command Say or SayEzb will be invoked by the plugin)
. A Command message containing EZB commands which will be invoked by the plugin

Text message Bot Response can be stored in an EZ Builder Variable which name can be set and changed in plugin configuration form.

User-inserted image

In the above Example :

The query message was "move forward at full speed"
Text Bot response message : 'I move forward"
EZB commands invoked : SetSpeed(255 , 255) then Forward()
the "|" character is just a CR/LF separator and is changed to CR/LF (As in an EZ Buider Script) when invoking the script.

Formatting the Bot response message in SIML files

When the query message match a Pattern defined in a Model Block , Bot response is created in the Response Block

Response block result is sent back to the plugin.
Only the last response (in case of [GOTO] redirections) is sent back to the plugin.

To avoid lost of multiple responses due to use of [GOTO] tag ,
SIML files Bot responses must be set as value of a USER variable named bot_event_response

Code:

[User xml:space="preserve" Think:Set="bot_event_response"]DURATION CANNOT BE SET FOR THIS MOVEMENT]/User>]


If a response is returned by the tag, this response will be also sent back to the plugin.
The query result will be the concatenation of this response and of the value of the bot_event_response USER variable.
This variable is reinitit for each new query.

In order to be able to include EZ Commands in the Bot response.
Response format must be coded in SIML as follow :

Text message§Script 1§Script 2§
or
Text message§Script 1§

the § character is only a separator.

A script is a sequence of EZ Buider commands as in an EZ Builder script , each command separated by the | character - equivalent to the CR/LF in an EZ Builder script.
2 scripts can be specified and invoked asynchronously in the plugin ( 2 executors are used )

in the example above , the Bot response message was formatted in SIML :
I move forward§SetSpeed(255 , 255)|Forward()§

the SIML code

Code:

[Model]
[Pattern]move forward at full speed[/Pattern]
[Response]
I move forward§SetSpeed(255 , 255)|Forward()§
[/Response]
[/Model]

or better

Code:

Model]
[Pattern]move forward at full speed[/Pattern]
[Response]
[User Think Set="bot_event_response"]I move forward§SetSpeed(255 , 255)|Forward()§[/User]
[/Response]
[/Model]



Stopping the Bot session

The bot session can be stopped :

By clicking the Stop Bot Button on the plugin Main Window

In EZ Scripts :

Code:

Botstop()

Or

Code:

ControlCommand("Synbot  plugin", Stop)


Context of BOT variables values and USER variable values for the userid is saved.

Example of linking to Bing Speech RecognitionControl

In you want that the Bing Speech Results will be used for querying the Bot , configure the "script to execute for each phrase detected " in Bing Speech Recognition plugin configuration form
User-inserted image

Code:

if (!$botstarted)
ControlCommand("Synbot plugin", Start)
sleep(1000)
endif
$botusermessage = $BingSpeech
ControlCommand("Synbot plugin", Query)


Lower Your Head is recognized

User-inserted image