Sarufi NodeJS SDK to help you interact with SARUFI platform inspired by Python Sarufi SDK
- Installation
- Use
- Login
- Create an empty chat bot
- Updating your bot
- Get bot
- Delete bot
- Start conversation
- Responses
From terminal in the root directory of your project, run
npm i sarufi
import sarufi from sarufi
We supply username and password for us to be able to login.
Request: From the imported
sarufi
, call
sarufi.login({username: "YOUR BEAUTIFUL USERNAME", password: "YOUR VERY STRONG PASSWORD"})
Response for successful login
{
"message": " You have logged in successfully",
"token": "YOUR BEARER AUTH TOKEN",
"success": true,
}
We supply chatbot details
Request payload
{
"name": "YOUR AWESOME BOT NAME",
"description": "PUT DESCRIPTION HERE",
"industry": "YOUR BOT INDUSTRY",
"intents": {},
"flows": {},
}
Then we call
sarufi.createBot({bot: REQUEST PAYLOAD})
NB:
For detailed description of intents and flows to be used in conversation, refer to Python Sarufi SDK Docs
Response for successful bot creation
{
"success": true,
"bot": { "name": "YOUR AWESOME BOT NAME",
"description": "PUT DESCRIPTION HERE",
"user_id": "YOUR ID",
"industry": "YOUR BOT INDUSTRY",
"intents": {}, //intents if they were supplied
"flows": {}, //flows if they were supplied
"updated_at": "DATE THE BOT WAS LAST UPDATED",
"id": "BOT ID",
"model_name": "BOT MODEL NAME",
"created_at": "DATE THE BOT WAS CREATED"
},
"chat": "({message: string, chat_id?: uknown}) => RETURNS CHAT RESPONSE" //A callable method that starts a chat with your bot, it takes in a string message and optional chat ID
}
Updating a bot, takes in the same arguments as creating a bot with addition of bot id
Request
sarufi.updateBot({bot: REQUEST PAYLOAD, id: YOUR BOT ID})
Response on success, is the same as the response for creating a bot
We call the following method on sarufi
and pass the bot id
Request
sarufi.getBot({id: BOT ID})
Response on success, is the same as the response for creating and updating a bot
We call the following method on sarufi
and pass the bot id
Request
//For version 0.0.1-Beta
sarufi.getBots()
//For versions 0.0.2-Beta and above,
sarufi.getBots({}) //This accepts optional paramemters url and token for persisted authorization tokens.
Response on success
{
"success": true,
"bots": [] //Array of all bots you created
}
We call the following method on sarufi
and pass the bot id
sarufi.deleteBot({id: BOT ID})
Response on success
{
"success": true,
"message": "A MESSAGE STATING THAT YOUR BOT HAS BEEN DELETED"
}
There are two methods for this, i.e
- bot.chat() this requires us to get a bot we want to have a conversation with and calling a chat method
- sarufi.chat() this requires a required message, required bot_id and an optional chat_id as request arguments
// bot.chat()
const bot = sarufi.getBot({id: 'OUR BOT ID'})
await bot.chat({message: 'Yooh'})
//sarufi.chat()
await sarufi.chat({message: 'Hey', bot_id: bot.id, chat_id: 'HEYOO',})
Response on success
{
"message": string| number | unknown | [string] | Record<string, unknown> | [Record<string, unknown>],
"success": true,
"memory": { [key: string]: string | unknown},
[key: string]: string | unknown
}
Success
property that shows whether or not the request was successful- For failed requests, the response's success property will be false and additional properties for tracing will be added to the response object
Example of failed request
{
"success": false,
"message": "MESSAGE", //an error message explaining the error
"code": "string",
"status": "NUMBER",
}
Although an error response can have more than those properties, when the status is 500, that will denote an error occured within the sarufi otherwise it will be from an error originating from the remote sarufi server.
NB
: For detailed documentation, please visit the Python Sarufi SDK Docs