Skip to main content

A8Chat Bot Task API

This is used to start a botpress flow in a messaging channel for the given user.

Each request from A8Flow to start a conversation with the given user is referred by the name "bot task" here.

The request should specify the user details with whom the chat conversation must be started by the bot. With this, the user must be able to be identified even if he is offline. Botpress flows can be built to handle these tasks. The request must have this flow name. The task will start the flow to the user in the specified messaging channel with the user details.

Given below are details of the APIs for creating and monitoring the tasks. Each request must have the API key in the authorization header.

Create or Start A Task

Request URL: https://livechat-testing.autonom8.com/

Request Method: POST

Request Header: Authorization: Bearer(API KEY)

Request JSON Body:

KEYTYPEDESCRIPTIONEXAMPLE/REMARKS
webhookstringThe webhook which should be called by the bot/agent to update details about the taskhttp://hdfc.autonom8.com/task/
userobjectDetails about the user to which the bot must start the conversation withSee user object payload
tagstringEasily readable name or identifier which can be used to group the tasks sent to a number of usershdfcSurvey
channelstringThe messaging or conversational platform of the user. Channels supported now: whatsapp, facebook, twitter, sms, and restwhatsapp
botHandlestringThe name or identifier of the bot which should start the conversationedgebot
bpFlowToTriggerstringThe name of the flow in botpress that this conversation should start withsurvery
contextobjectCustom data which should be passed to the flow{"employee": "", "startDate": ""} This is an optional field.

User Object Payload:

KEYTYPEDESCRIPTIONEXAMPLE/REMARKS
userIdstringThe user identifier to which the chat is initiated. In case of whatsapp channel, this could be mobile number. For facebook it is page specific user Id or PSID.919876543210
usernamestringName of the userUsername(This is an optional field)

Response JSON Body: The request will return a task ID which can be used to stay updated with the changes.

Sample Response: { "taskId" : "5f16c55e0340eb3554fc059b" }

Get Task Details

Request URL: https://livechat-testing.autonom8.com/

Request Method: GET

Request Header: Authorization: Bearer(API key)

Response JSON Body:

KEYTYPEDESCRIPTIONEXAMPLE/REMARKS
webhookstringThe webhook which should be called by the bot/agent to update details about the taskhttp://hdfc.autonom8.com/task/(taskID)
idstringThe task identifier5f16c55e0340eb3554fc059b
tagstringEasily readable name or identifier which can be used to group the tasks sent to a number of usershdfcSurvey
clientIdstringThe user identifier used in A8Chatwhatsapp_919876543210_A8Chat_edgebot
botHandlestringThe name or identifier of the bot which handles the conversationedgebot
flowToTriggerstringThe name of the flow in botpress that this conversation started withsurvey
orgIdstringIdentifier of the organization handling the task
statusstringCurrent status of the taskIt has three states like new, inprogress(bot is handling the task), and done(task is completed).
contextobjectCustom data that was passed to the flow{"employee": "", "startDate": ""} Any custom data can be passed as an object.
resultobjectEnd payload that is sent to the requester via webhook. This is stored only when the task is completed (done state){"rate" : "Good","reason" : "It was fast"}. Any custom data that the bot sends back as the response of the whole task.

Get Task Details using Tag Name

Request URL: https://livechat-testing.autonom8.com/

Query Parameter: tag=[tag name]

Request Method: GET

Request Header: Authorization: Bearer(API key)

Response: Array of tasks with the given tag name in the org.

Botpress Events to Update/End Task

Update Task

The bot can update values to the requester by calling the updateTask event. This event gets the current event states and the payload to update. With the event state values, the payload is sent to the webhook of the requester.

bp.events.updateTask(event, value) event : Incoming event value : Payload that is to be sent to the requester ( A custom object) Sample usage of the updateTask event in a botpress action.

function action(bp: typeof sdk, event: sdk.10.IncomingEvent, args: any, { user, temp, session } = event.state)

{

/** Your code starts below */

/**
* updateSurveyResults
* @title update survery results
* @category A8chat
* @author Autonom8

*/

const updateSurveyResults = async () => {
let value = {}
if (temp.rate != '') {
value['rate'] = temp.rate
}
if (temp.reason != '') {
value['reason'] = temp.reason
}
if (temp.toadd I= '') {
value['toAdd'] = temp.toAdd
}
await bp.events.updateTask(event, value)

}

return updateSurveyResults()

/** Your code ends here */
}

End Task

After completing the task, the bot can send the values to the requester by calling the endTask event. This event gets the current event states and the payload to send to the requester. With the event state values, the payload is sent to the webhook of the requester and the task is moved to done state.

bp.events.endTask(event, value) event : Incoming event value : Payload that is to be sent to the requester ( A custom object)

Sample usage of the endTask event in a botpress action

function action(bp: typeof sdk, event: sdk.10.IncomingEvent, args: any, { user, temp, session } = event.state)

{

/** Your code starts below */

/**
* endSurvey
* @title End survey
* @category A8chat
* @author Autonom8

*/

const updateSurveyResults = async () => {
let value = {
rate = temp.rate,
reason: temp.reason,
toAdd: temp.toAdd
}
await bp.events.endTask(event, value)

}

return updateSurveyResults()

/** Your code ends here */
}