API - English version

Integrations basics

Integration is anything which enables chatbot to connect with outside world. It could be initiated by the chatbot using step on certain point in the chatbot tree or in the opposite by some external system by triggering some of bot APIs.

Integration step

Integration step could be added to any place of chatbot tree and is triggered in the moment when any user is passing given point in the conversation. It can call any of supported APIs, pass parameters inside (static or dynamic based on data we already know about the user using variables) and store results for further usage.

Use-cases

Architecture

Every integration step type consists of two parts. First of them is JSON schema which describes what input parameters of which types are expected, which of them are required and what output structure should be expected. Second part is the code itself which implements:

In ideal case, integration step performs just a single API call but in some advanced scenarios it is often needed to perform multiple calls and combine input/output data to fulfill desired goal.

Advanced topics

Timing

Integration step could behave in three different ways from the point of view of timing and performance.

Level of abstraction

It is very important to consider which level of abstraction use during the process of integration step design. For example imagine that we have some system called "MyCRM" with a lot of modules with REST API which can perform insert/update/delete operations on any of them when every module has different set of fields. Goal of prepared integration is just to add customer with given name and email. Now we have at least three levels of abstraction to choose from:

It could not be said in a generic way which of these levels is correct. It always depends on given use-case, specs of used API and plans for future modifications of logic by non-programmers.

Channels

Channel is used to transfer messages from bot the user and back. We have some channel integrations built in the product itself, but it is possible to integrate any custom chat channel with proper API. There are three ways how to do it:

Some chat channels also support transferring events during the same "pipe" which is used for messages. Example could be WebChat component which allows:

Dialog trigger

External system can trigger selected dialog for given user by calling Trigger API which has following parameters:

You can read more in Trigger API documentation.

User data export

There is an API exposed by every running chatbot which could be used to retrieve all stored data for every user. This API is mainly used for analytic purposes (such as how many users have passed certain point in the tree - and thus have given storage filled) but also could be used for anything else. There are available basic parameters that could be used to filter out only given subset of users.

You can read more in Export API documentation.

Preset integrations

There is already a lot of integrations already implemented in Feedbot Designer. You can check this spreadsheet to find out more. It is important that every system could be integrated in large number of different ways with different options so it is needed to consider given use-case carefully. 

API automation platforms

Not all integrations needs to be programmed directly in the bot's code. Different kinds of automation/integration platforms or tools could be used to connect different services including bot to implement needed logic. Good examples of these platforms could be:

Adding new integrations

Following list tells what is often needed to have to allow new integration to be implemented:

Export API

Base URL for export API is bot-specific https://feedbot-${BotId}.azurewebsites.net. Please use the ?code=...query param or x-functions-key: ... HTTP header to perform token based authentication.

Get users data

Calling this endpoint without timestamp filters can return very large amount of data and affect bot performance. Regular daily fetching of data from the past day is recommended approach.

GET /api/management/export/userData

Returns list of objects containing all user-scoped data which bot persists. Optional filters parameters:

userId
timestamp
... all storages in camelCase ... 
Examples

Get users data snapshot

This API method is available since bot hosting version v1.7.474

GET /api/management/export/userDataSnapshot

Returns list of objects containing all user-scoped data snapshots (generated by the "clear user data" action) which bot persists. Usage and all params are the same as in "Get users data" API. 

userId
timestamp
... all storages in camelCase ... 

Get NLP logs

This API method is available since bot hosting version v1.7.474

GET /api/management/export/nlpLog

Returns list of objects containing all inputs entered by the user which was not possible to process using conversation tree. Desired time range could be specified using fromTimestamp and toTimestamp second-based UNIX timestamp.

userId
timestamp
dialogId
stepId
stepType
query
modelId
intent
result
processed

Get outgoing emails

This API method is available since bot hosting version v1.7.474

GET /api/management/export/outgoingEmail

Returns list of objects containing all emails sent by the chatbot incl. recipient, subject, body. Desired time range could be specified using fromTimestamp and toTimestamp second-based UNIX timestamp.

userId
timestamp
body
from
recipients
replyTo
stepId
subject

Get outgoing SMS

This API method is available since bot hosting version v1.7.474

GET /api/management/export/outgoingSms

Returns list of objects containing all SMS messages sent by the chatbot. Desired time range could be specified using fromTimestamp and toTimestamp second-based UNIX timestamp.

userId
timestamp
channel
link
message
provider
recipients

Get fuzzy question answers log

This API method is available since bot hosting version v1.7.474

GET /api/management/export/fuzzyQuestionAnswerLog

Returns list of objects containing all utterances processed by the fuzzy question answer plugin. Desired time range could be specified using fromTimestamp and toTimestamp second-based UNIX timestamp.

userId
timestamp
intent
score
text
stepId
dialogId
matched
otherClassifications

Get integration log

This API method is available since bot hosting version v1.7.474

GET /api/management/export/integrationLog

Returns list of objects containing all integration invocations. Desired time range could be specified using fromTimestamp and toTimestamp second-based UNIX timestamp.

userId
timestamp
url
method
requestBody
requestHeaders
responseStatus
responseBody
duration

 

Get URL tracker

This API method is available since bot hosting version v1.7.474

GET /api/management/export/urlTracker

Returns list of objects containing row for every click on URL button in bot by every user including target URL and domain. Desired time range could be specified using fromTimestamp and toTimestamp second-based UNIX timestamp.

userId
timestamp
domain
url

 

Trigger API

The Trigger API can be used to invoke a specific dialog for a selected user in a virtual assistant initiated by an external system.

Each bot runs on its own domain (usually in the format https://feedbot-${BOT_ID}.azurewebsites.net) and is protected by a key in either  ?code=... URL query parameter or x-functions-key: ... HTTP header.

POST /api/management/trigger/${ADDRESS_JSON_AS_BASE64}/${DIALOG_ID}/${MODE?}

Example of use

External API recommendations

It is possible to prepare any number of "integration steps" in the virtual assistant, which are points in the conversation tree where the virtual assistant uses the API to integrate with another system in order to obtain some data necessary for its function or, conversely, to send some data that it has detected from the user to the system.

The virtual assistant can adapt quite a bit to the format and structure of the API, but if the API is created for the sake of the virtual assistant, the following recommendations can be followed to make the implementation as smooth as possible.

Recommended API properties
Sample

The virtual assistant can use the API to retrieve a list of scheduled events from the dependent system. The user IDs are passed, for example, to a WebChat component inside an internal system where the user is already authenticated. The data is used by the bot to display a "carousel" of scheduled events, where the user can select one of them and continue with some other action.

GET https://somedomain.cz/api/v1/user/33/events

Authorization: Bearer ...
Content-type: application/json

→ 200 [{"id":"1", "name":"Onboarding meeting", "date":"2020-05-07T08:22:30.871Z"}]

At the end of the communication, the virtual assistant can send information about the newly acquired user to the CRM. The request can include all the data that the virtual assistant has collected about the user.

POST https://somedomain.cz/api/v1/user

Authorization: Bearer ...
Content-type: application/json
{"email": "user@example.com", "name":"Jack", "surname":"User", "interestedInProductIds": [244, 234]}

→ 200 {"id":"433"}