Bot Setup APIs
1. Overview
UCI provides a list of apis that will help you to configure bots for conversation or broadcasting.
2. APIs
To setup a bot and start conversation with users, the following steps need to be followed.
2.1 Add adapter
Add a new adapter for the available channel & providers. Below is a list of available parameters.
name: Name of the adapter
channel: Messaging channel.
provider: Message provider
config:
credentials:
vault: Vault service name, Default value: samagra
variable: Variable name added in the vault.
List of available channel and provider combinations:
provider: netcore, channel: whatsapp
provider: gupshup, channel: whatsapp
provider: gupshup, channel: sms
provider: cdac, channel: sms
provider: firebase, channel: web
Note: If you need some other channel or provider, contribute a new adapter for the same. Click here to see how to do this.
Below is a curl request for adding a new adapter in db. This adapter will be associated with a bot to determine the channel and provider for the bot when conversing.
This API will create a new adapter and will return the adapter id (Eg. 2a704e82-132e-41f2-9746-83e74550d2ea). We can use this adapter id later in create conversation logic api.
2.2 Creating a Conversation Bot
A conversation bot is used to communicate with the user one on one. A chatbot uses a flow defined in an odk xml form to chat with a user. The steps for creating a simple conversation chatbot are given below.
2.2.1 Upload ODK Form
For using ODK transformer, we will first have to upload a ODK form. Follow below steps to upload a ODK form.
Convert a ODK Excel form to XML form using Link.
Here is a Sample ODK Excel Form for reference.
Upload this XML from using this api.
Response: The API will return a form id. Use this form id to create conversation logic API. Form id E.g. testing_form
2.2.2 Add a Conversation Logic
For any bot we will have to specify a certain configuration which is a part of conversation logic. Below is a list of available parameters.
name: Conversation logic unique name
transformers: Array of transformers
id: id of transformer
meta:
formID: uploaded odk form id from upload form api (For ODK transformer)
params: Array of parameters to be used in template **** message (For Broadcast transformer)
body: (For Broadcast transformer)
type: type of template (For Broadcast transformer), Default. JS_TEMPLATE_LITERALS
type: type of transformers (Eg. broadcast/generic) ****
adapter: id **** of adapter from add adapter api.
Use below curl to create a conversation logic.
Response: It will return a conversation logic id, use it in create bot. Eg. be37c9f2-7f2b-4e19-b525-33b0a2aabdd5
2.2.3 Configure a bot
After the conversation logic is defined, we can use this to create a new bot. This bot must include a starting message as we will use this to start a conversation for this bot. Below is a list of available parameters.
startingMessage: unique message to start conversation.
name: unique name of bot.
users: array of user segment ids, currently the first one will be used.
logic: array of conversation logic ids from add logic api, currently the first one will be used.
status: status of bot, Eg. draft/disabled/enabled.
startDate: date from which bot will be active.
endDate: date till which bot will be active.
Use below curl to create a conversation logic.
Response: This api will return a bot id & other bot information. Use the starting message (Eg. Hi Bot) from here to start a conversation with a bot.
2.3 Creating a Broadcast Bot (Optional)
2.3.1 Add a User Segment
User segment contains the group of users to whom the broadcast would be sent out to.
Use the curl below to create a user segment.
Response: It will return a response containing the id of the segment that is created. Eg. 2ddea169-2db9-442b-99f2-fc85c9ea1a02
2.2.4 Add a Broadcast bot
After the conversation logic is defined, we can use this to create a new bot. This bot must include a starting message as we will use this to start a conversation for this bot. Below is a list of available parameters.
startingMessage: unique message to start conversation
name: unique name of bot ****
users: array of user segment ids, currently the first one will be used
logic: array of conversation logic ids from add logic api, currently the first one will be used
status: status of bot, Eg. draft/enabled
startDate: date from which bot will be active
endDate: date till which bot will be active
Use below curl to create a conversation logic.
Response: This api will return a bot id & other bot information. Use the starting message (Eg. Hi Test ODK) from here to start conversation with a bot.
Last updated
Was this helpful?