Skip to main content
Conversation

Chatbots send voucher code to customers via API

by content 04.08.2020

Nowadays, chatbots are commonly used in many fields such as finance - banking, insurance, etc. to maintain and take care of the relationship between customers and businesses. Especially, in the e-commerce industry, chatbots can perform many tasks.

When building a bot, besides scripts to answer Frequently asked questions (FAQs), chatbots can also perform many other scenarios such as Product information lookup, Customer information collection, Ordering, Booking/canceling tickets, etc. These tasks need access to companies’ databases to store or retrieve information to give customers accurate responses. FPT.AI chatbot has many outstanding features such as JSON API card, CRM card, etc. that meet rigorous requirements of businesses.

 With FPT.AI Conversation, chatbot script builders can take the initiative in designing the flow, to determine what time and data to interact with the system through JSON API card.

Here is the technical model that FPT.AI Conversation is applying:

In this model, to make the connection to backend systems of businesses, we need to build a component called middleware, which takes care of these tasks:

  • Be a communication intermediary between chatbots and backend systems of enterprises, perform the conversion from the protocol (if any, such as SOAP) to the Restful protocol.
  • Provide APIs in Restful standard and JSON format, which specified by FPT.AI platform to integrate into chatbot scenario.
  • Connect to businesses’ backend to do tasks on the chatbot scenarios.
  • Perform additional functions such as statistics, reports, etc.

This middleware component will be deployed on businesses' environment.

In this article, the author will solve the problem of providing customers a voucher code when they complete a scenario (assume they clicked on the voucher button).

First of all, we need to determine the scenario and declare variables:Chatbot FPT.AI

Chatbot FPT.AI

When customers click on the "Get voucher" button, chatbots will perform the "Receive voucher" step:Chatbot FPT.AI

In this script, we can flexibly add more variables to API as needed. They could be system-created variables or user-created variables. We can also add variables returned from API to create scenarios flexibly to meet the needs of the business.

For JSON-API card, you can use variables or constants on URLs, headers, for example, https://api-url/{{sender_id}}. To minimize the need to edit values ​​for different environments (dev, prod), you should declare constants and use constants for this case as the API-KEY example in the image above.

With the HTTP POST method, note that the system will use content-type = application/json. The results returned from API follow this structure:Chatbot FPT.AI

The bolded properties require exact names. The set_attributes feature is a list of variables that need to return to the bot, and the variable list follows this structure:Chatbot FPT.AI

API also supports sending direct messages to customers with the message list structure above. In the case when messages have button and payload, the payload will be a chain with structure <Step name>#base64(payload_data). Playload_data is a JSON chain including a list of variables like the set_attributes structure above. When customers click on the button containing the payload data, the value of variables will be passed to that step and can be used as normal variables.

For example, with API Get voucher code as above through the POST method, we can do it in the PHP language as bellow:

Chatbot FPT.AI

Thus, we have completed the integration of chatbot into the backend systems of the enterprise. You can also build your APIs so that chatbots can perform more specialized tasks.

Once completed, the user interface will display as below:

Easily integrated on popular chat interfaces such as Facebook Messenger, Zalo, Website, chatbots built on FPT.AI Conversation platform allow users to interact directly with businesses through natural conversations, support 1-1, become an effective "virtual assistant" to bring customers useful experiences.

------------------------------------

Experience the #FPT_AI products at: https://fpt.ai/en/

☎ Hotline: 0911886353

? Email: [email protected]