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.
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.
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.
curl --location 'http://http//UCI_API:PORT/admin/bot' \
--header 'asset: bot' \
--header 'admin-token: dR67yAkMAqW5P9xk6DDJnfn6KbD4EJFVpmPEjuZMq44jJGcj65' \
--header 'Accept: application/json, text/plain, */*' \
--header 'ownerOrgID: org01' \
--header 'ownerID: 8f7ee860-0163-4229-9d2a-01cef53145ba' \
--form 'botImage=@"{PATH_TO_IMAGE}"' \
--form 'data="{
\"data\": {
\"name\": \"TEST BROADCAST BOT\",
\"description\": \"TEST\",
\"purpose\": \"TEST\",
\"startingMessage\": \"Hi Test Broadcast\",
\"startDate\": \"2023-06-16\",
\"endDate\": \"2023-06-30\",
\"isBroadcastBotEnabled\": true,
\"segmentId\": \"1\",
\"status\": \"enabled\",
\"users\": [
\"2ddea169-2db9-442b-99f2-fc85c9ea1a02\" // Get this id from user segment api response
],
\"logic\": [
\"be37c9f2-7f2b-4e19-b525-33b0a2aabdd5\" // Get this id from conversation logic api response
]
}
}"'
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.