Rivescript_Tags

Rivescript_Tags

Some custom tags use Facebook Messenger API format to send messages directly from rivescript
Source:

Members

attachment

Adds a facebook attachment as a response line - Can be an image, audio or video
Source:
Examples

How to use

<attachment String|Array>

This will get an attachment named nude from attachment object file

<rivescript>

+ Send me a picture
- Ok\n
^ <attachment nude>

</rivescript>

This will get some attachments from attachment object file

<rivescript>

+ Send me some pictures
- Ok\n
^ <attachment ["nude", "car", "apple"]>

</rivescript>

This will get some attachments from attachment object file - template

<rivescript>

+ Send me some pictures
- Ok\n
^ <attachment [\s
^    {\s
^        type: "image",\s
^        url: "http://www.images.com.br/image.jpg"\s
^    },\s
^    {\s
^       type: "audio",\s
^       url: "http://lh5.ggpht.com/audio.mp3"\s
^    }\s
^ ]>\s

</rivescript>

br

Breaks the line inside the same "balloon" in the chat
Source:
Examples

How to use

<br>
<rivescript>

+ What is your status?
- Good<br>pra<br>carai

+ What is your status again?
- Very<br>good<br>pra<br>carai

</rivescript>

button

Adds a facebook button in response line - If the menu has an title, the menu title will be used, if not the title will be the line text
Facebook Reference
Source:
Examples

How to use

<button String|Array|Object Object|Array>

If you only send an array of strings, all payloads will be cmdr(x) where x is the array index + 1, Eg. cmdr1, cmdr2 and so on...

<rivescript>

+ You can go there
- Ok, but what side I must choose? <button ["Left", "Right"]>

</rivescript>

The second param can be an array with integers and is for conditional show of the button, where 1 will show and 0 will hide the button

<rivescript>

+ You can go there
- Ok, but what side I must choose? <button ["Left", "Right", "Maybe"] [1, 0, 1]>

</rivescript>

You can call a menu from menu object file, if configured - template

<rivescript>

+ You can go there
- Ok, but what side I must choose? <button menu_from_file [1, 0, 1]>

</rivescript>

This will print the button directly from rivescript

<rivescript>

+ You can go there
- Ok, but what side I must choose?\s
^ <button [\s
^    {\s
^        title: "Title",\s
^        webview_height_ratio: "tall",\s
^        messenger_extensions: true,\s
^        url: "https://google.com.br"\s
^    },\s
^    {\s
^        title: "Fly",\s
^        payload: "cmdfly"\s
^    }\s
^ ]>\s

</rivescript>

You can get a button from a script - the first param can be an object with pair of key/value to pe passed to the function getMenu on menus object configured - template

<rivescript>

+ You can go there
- Ok, but what side I must choose? <button {facebook_id:"1234567891010"} [0, 0, 1]>

</rivescript>

delay

Delays a bot response line by a given number of seconds
Source:
Examples

How to use

<delay Number>
<rivescript>

+ Can you get me a bottle?
- Whait...\n
^ <delay 30>I get it! here

</rivescript>

if

If statement to be used for conditional words inside rivescript replies
Source:
Examples

How to use

{if conditional}String{else conditional}String{/if}
<rivescript>

+ What is your gender?
- {if gender=="male"}Male{else gender=="what"}?{else}Female{/if}

</rivescript>

if

If statement to be used for conditional a single line
Source:
Examples

How to use

<if conditional>

The bot will respond only "But not so good!" If conditions are false and Ok, But not so good! and conditions are true

<rivescript>

+ What is your status?
- <if (health>5&sanity>3|stamina<3)>Ok\n
^ But not so good!

</rivescript>

ifbreak

If statement to be used for conditional lines, but if the condition is false no more lines will be returned after that
Source:
Examples

How to use

<ifbreak conditional>

The bot will respond nothing if conditions are false

<rivescript>

+ What is your status?
- <ifbreak (health>5&sanity>3|stamina<3)>Ok\n
^ Please Helpe me!

</rivescript>

next

Call a bot again from one to X times can be used to redirect after do something on a database, for exemple
Source:
Examples

How to use

<next String|Array>
<rivescript>

+ What is your name?
- <next ["nextline", "lastline"]>

+ nextline
- I do not know

+ lastline
- Can you help me remember?

</rivescript>
+ What is your name?
- <next nextline>

+ nextline
- Mike

</rivescript>

nrsp

Returns an empty string (can be used for pauses in text)
Source:
Examples

How to use

<nrsp>
<rivescript>

+ What is your status?
- <nrsp>

</rivescript>

quickreply

Adds a facebook quickreply in response line, if you use more lines after that, will break the buttons - If the menu has an title, the menu title will be used, if not the title will be the line text
Facebook Reference
Source:
Examples

How to use

<quickreply String|Array|Object Object|Array>

If you only send an array of strings, all payloads will be cmdr(x) where x is the array index + 1, Eg. cmdr1, cmdr2 and so on...

<rivescript>

+ You can go there
- Ok, but what side I must choose? <quickreply ["Left", "Right"]>

</rivescript>

The second param can be an array with integers and is for conditional show of the button, where 1 will show and 0 will hide the button

<rivescript>

+ You can go there
- Ok, but what side I must choose? <quickreply ["Left", "Right", "Maybe"] [1, 0, 1]>

</rivescript>

You can call a menu from menu object file, if configured - template

<rivescript>

+ You can go there
- Ok, but what side I must choose? <quickreply menu_from_file [1, 0, 1]>

</rivescript>

This will print the quickreply directly from rivescript

<rivescript>

+ You can go there
- Ok, but what side I must choose?\s
^ <quickreply [\s
^    {\s
^        content_type: "text",\s
^        title: "Left",\s
^        payload: "Leftcmd"\s
^    },\s
^    {\s
^        content_type: "text",\s
^        title: "Right",\s
^        payload: "rightcmd"\s
^    }\s
^ ]>\s

</rivescript>

You can get a quickreply from a script - the first param can be an object with pair of key/value to pe passed to the function getMenu on menus object configured - template

<rivescript>

+ You can go there
- Ok, but what side I must choose? <quickreply {facebook_id:"1234567891010"} [0, 0, 1]>

</rivescript>

save

Saves the entire line and pass as variable to be reused
Source:
Examples

How to use

<save>
<rivescript>

+ What is your status?
- Good <save>

+ What is your status again?
- <get storage>

</rivescript>

script

Calls an external script
Source:
Examples

How to use

<script String|Object|Array Object> or <js String|Object|Array Object>

Rivescript part

<rivescript>

+ Give some information
- OK! <js getDataFromDataBase>

</rivescript>

Javascript part

function getDataFromDataBase(botData, params)
{
     //do all the stuff
}

Rivescript part

<rivescript>

+ Give some information about id #
- OK! <js getDataFromDataBase {id:"<star>"}>

</rivescript>

Javascript part

function getDataFromDataBase(botData, params)
{
     var id = params.id;
     //do all the stuff
}

Rivescript part

<rivescript>

+ Give some information and update
- OK! <js ["getDataFromDataBase", "updateUserData"]>

</rivescript>

Javascript part

function getDataFromDataBase(botData, params)
{
     //do all the stuff
}

function updateUserData(botData, params)
{
     //do all the stuff
}

Rivescript part

<rivescript>

+ Give some information
- OK! <js [{name: "pause", param:{id:"id", title:"title"}}, {name: "start"}]>

</rivescript>

Javascript part

function pause(botData, params)
{
     var id = botData.param.id;
     var title = botData.param.title;
     //do all the stuff
}

function start(botData, params)
{
     //do all the stuff
}

template

Adds a facebook template in response line
Facebook Reference
Source:
Examples

How to use

<template String|Array|Object Object|Array>

If you only send an array of strings, all payloads will be cmdr(x) where x is the array index + 1, Eg. cmdr1, cmdr2 and so on...

<rivescript>

+ You can go there
- Ok, but what side I must choose?\n
^ <template ["Left", "Right"]>

</rivescript>

The second param can be an array with integers and is for conditional show of the template, where 1 will show and 0 will hide the template

<rivescript>

+ You can go there
- Ok, but what side I must choose?\n
^ <template ["Left", "Right", "Maybe"] [1, 0, 1]>

</rivescript>

You can call a menu from menu object file, if configured - template

<rivescript>

+ You can go there
- Ok, but what side I must choose?\n
^ <template menu_from_file [1, 0, 1]>

</rivescript>

This will print the template directly from rivescript

<rivescript>

+ You can go there
- Ok, but what side I must choose?\n
^ <template [\s
^    {\s
^       title: "item 1",\s
^       subtitle: "description 1",\s
^       image_url: "item 1 image",\s
^       buttons:\s
^       [\s
^            {\s
^                title:"button 1",\s
^                webview_height_ratio: "tall",\s
^                messenger_extensions: true,\s
^                send_id: true,\s
^                encode_id: true,\s
^                url: "url"\s
^            }\s
^        ]\s
^     },\s
^     {\s
^        title: "item 2",\s
^        subtitle: "description 2",\s
^        image_url: "item 2 image",\s
^        buttons:\s
^        [\s
^            {\s
^                title:"button 2",\s
^                payload: "cmdopen"\s
^             }\s
^        ]\s
^     }\s
^ ]>\s

</rivescript>

You can get a template from a script - the first param can be an object with pair of key/value to pe passed to the function getMenu on menus object configured - template

<rivescript>

+ You can go there
- Ok, but what side I must choose?\n
^ <template {facebook_id:"1234567891010"} [0, 0, 1]>

</rivescript>

update

Updates a table with the given data - The object has the keys as the tables names and value as an object with the fields
Source:
Examples

How to use

<update Object>
<rivescript>

+ You can use the health kit
- Thanks! <update {tbl_character: {health: "+3", "sanity: "/2","hunger: "*2"}, tbl_user:{email: "besta@gmail.com"}}>

</rivescript>

var

Custom variable to be used after rivescript response, if you have some data that isn't sent by user data
Source:
Examples

How to use

<var String>
<rivescript>

+ What is your name?
- <var first_name>

</rivescript>