robo-js-sdk
Welcome to our robo-js-sdk tutorial.
What is this SDK for?
This is a Javascript SDK to access the ROBO.AI API.
Import into your project
Import it as a module
robo-js-sdk
is available on npm. To install it just execute:
$ npm install robo-js-sdk
Then you can import the RoboAi SDK class into your code:
import RoboAi from "robo-js-sdk";
In the browser
You can also use it directly within the browser, for example using unpkg:
<script src="//unpkg.com/robo-js-sdk@latest/dist/roboAi.js"></script>
Usage
After importing the RoboAi class you can initialize a new instance:
const config = {
url: "<BACKEND_URL>",
apikey:"<API_KEY>", // Use your ROBO.AI account to generate an API key
basicAuth: {
user: "<BASIC_AUTH_USERNAME>",
psw: "<BASIC_AUTH_PASSWORD>"
}
};
const roboAi = new RoboAi(config);
Available methods
To list assistants:
roboAi.getAssistants()
Using this method will return an array of assistants like this:
[
{
"uuid": "bot-uuid",
"name": "bot-name",
"description": "I am a bot",
"displayName": "Helena",
"created": "2020-03-25T11:52:42.000+0000",
"updated": "2021-02-02T15:58:59.000+0000",
"status": "ENABLED/DISABLED"
}
]
To get a specific assistant;
const assistantUuid = "bot-uuid"
roboAi.getAssistant(assistantUuid)
Using this method will return a specific assistant like this:
{
"uuid": "bot-uuid",
"name": "bot-name",
"description": "I am a bot",
"displayName": "Helena",
"created": "2020-03-25T11:52:42.000+0000",
"updated": "2021-02-02T15:58:59.000+0000",
"status": "ENABLED/DISABLED"
}
To start a dialogue with a specific assistant;
const assistantUuid = "bot-uuid"
roboAi.startDialogue(assistantUuid)
Using this method will return a response like this:
{
"message": "text",
"dialogueUuid": "0be3b300-54ba-4220-9059-e2a86ffe2208",
"answers": [
{
"type": "ssml",
"ssml": "<speak>Hi, how can I help?</speak>"
},
{
"type": "text",
"text": "Hi, how can I help?"
}
],
"assistantUuid": "bot-uuid"
}
To send a message within a dialogue;
const dialogueUuid = "0be3b300-54ba-4220-9059-e2a86ffe2208"
const messageRequest = {
message: 'text',
};
roboAi.sendMessage(dialogueUuid, messageRequest)
Using this method will return a response like this:
{
"message": "text",
"dialogueUuid": "0be3b300-54ba-4220-9059-e2a86ffe2208",
"answers": [
{
"type": "ssml",
"ssml": "<speak>I am a bot</speak>",
"audio": "bsbygydhbddjddu...",
"audioContentType": "audio/mp3"
},
{
"type": "text",
"text": "I am a bot"
}
],
"assistantUuid": "martin---status-tracking-es"
}
To send an event within a dialogue;
const dialogueUuid = "0be3b300-54ba-4220-9059-e2a86ffe2208"
const eventRequest = {
type: 'command',
name: 'test',
params: [
{
key: 'key',
value: 'value',
},
],
};
roboAi.sendEvent(dialogueUuid, eventRequest)
Using this method will return a response like this:
{
"message": "{\"type\":\"command\",\"name\":\"test\",\"params\":[{\"key\":\"key\",\"value\":\"value\"}]}",
"dialogueUuid": "0be3b300-54ba-4220-9059-e2a86ffe2208",
"answers": [
{
"type": "ssml",
"ssml": "<speak>This is an answer.</speak>"
},
{
"type": "text",
"text": "This is an answer."
}
],
"assistantUuid": "martin---status-tracking-es"
}
To send feedback;
const dialogueUuid = "0be3b300-54ba-4220-9059-e2d86ffe2208"
const feedback = {
questions: ['Test question 1?', 'Test question 2?', 'Test question 3?'],
expectedAnswer: 'expected answer',
trustedSourceUrl: 'http://trustedurl.example',
};
roboAi.feedback(dialogueUuid, feedback)
Using this method will return a response like this:
{
"dialogueUuid": "0be3b300-54ba-4220-9059-e2d86ffe2208",
"answers": [
{
"type": "ssml",
"ssml": "<speak>I am a bot.</speak>"
},
{
"type": "text",
"text": "I am a bot"
}
]
}
To send Conversation Rating;
const dialogueUuid = "0be3b300-54ba-4220-9059-e2d86ffe2208"
const rating = {
sentiment: 'GOOD', // possible values are: 'GOOD', 'BAD', 'NEUTRAL',
comments: 'I love this bot'
};
roboAi.rating(dialogueUuid, rating)
Using this method will return a string response like this:
"sucess"