Different APIs that Can be Used on Conversation Studio
- Getting Started
- Bot Building
- Smart Agent Chat
- Conversation Design
-
Developer Guides
Code Step Integration Static Step Integration Shopify Integration SETU Integration Exotel Integration CIBIL integration Freshdesk KMS Integration PayU Integration Zendesk Guide Integration Twilio Integration Razorpay Integration LeadSquared Integration USU(Unymira) Integration Helo(VivaConnect) Integration Salesforce KMS Integration Stripe Integration PayPal Integration CleverTap Integration Fynd Integration HubSpot Integration Magento Integration WooCommerce Integration Microsoft Dynamics 365 Integration
- Deployment
- External Agent Tool Setup
- Analytics & Reporting
- Notifications
- Commerce Plus
- Troubleshooting Guides
- Release Notes
Table of Contents
Move a chat to pendingGet Chat Transcripts v2.0FAQ Step Creation APIs for KMSPolling API to fetch submitted task StatusBest PracticesMove a chat to pending
This API allows you to move chats for a Bot to an Agent via a POST
request to the Haptik Platform.
Example URL: https://<base-url>/integration/external/v2.0/send_chat_to_agent/
Headers
Authorization: Bearer <TOKEN> client-id: <CLIENT_ID> Content-Type: application/json
Request
{ "team_name": "<Name of the team>", "user_name": "<haptik user name>", "business_id": "<business_id>", "countdown": "<time_in_seconds>", "receiver": "athena" }
user_name (string): Identifier for the User provided by Haptik when invoking the Integration API
business_id (number): This is a numeric identifier for the channel where the User is messaging
team_name (string): Name of the team to which the chat is to be assigned. Can be fetched from the Teams page of Agent Chat Tool.
countdown (number): If value is set to 5, then after 5 seconds chat will be moved to the queue. Otherwise, the chat will be moved to the queue after 10 seconds (default), value can be from range 5 to 10 seconds.
receiver (athena): Athena is Haptik's internal Smart agent chat. This helps identify to if the chat transfer should happen to SAC.
Response
A successful request to the API will return a 200
status code with a JSON response object.
{
"success": true
}
- success: Indicates if the API was a success or failure
Error Response
If there is an error in the Headers or the Request body, then the Error message will be returned in a JSON as shown below:
{
"error_message": "user is not registered"
}
Here is a list of some possible error messages
Error Message | Details |
---|---|
client_id missing in headers | client-id is not passed in the Headers of the request |
invalid client_id in headers | Incorrect client-id is passed in the headers |
invalid authorization in headers | The Authorization header is not correct |
token missing in headers | The Authorization token is not provided |
invalid token provided | The Authorization token provided is incorrect |
user_name missing in the request | The user_name is not provided in the request body |
business_id missing in the request | The business_id is not provided in the request body |
team_name missing in the request | The team_name is not provided in the request body |
invalid user_name | The user_name provided is not valid for the Account |
invalid business_id provided | The business_id provided is not valid for the Account |
business "<business_id>" is inactive | The business is inactive for the Account |
invalid team_name provided | The team_name is not valid for the Account |
team "<team_name>" is inactive | The associated Team is inactive |
user has not sent a message | The user has not had any chat on that Business |
Sample CURL command
curl -X POST \ https://<base-url>/integration/external/v2.0/send_chat_to_agent/ \ -H 'Authorization: Bearer <TOKEN>' \ -H 'client-id: <CLIENT_ID>' \ -H 'Content-Type: application/json' \ -d '{ "team_name": "<Name of the team>", "user_name": "<haptik user name>", "business_id": <business_id>, "receiver": "athena" }
Get Chat Transcripts v2.0
This API allows you to get the chat history of the user for a conversation via a GET
request to the Haptik Platform.
Example URL: https://<base-url>/integration/external/v2.0/get_chat_history/
Headers
Authorization: Bearer <TOKEN>
Client-ID: <CLIENT_ID>
Content-Type: application/json
Request parameters
parameter | type | required | group | description |
---|---|---|---|---|
business_id | str(int) | grouped | 1 | Business ID for |
user_name | str | grouped | 1 | Haptik user name. |
conversation_no | int | true | 1/2 | Conversation number of user's chat. |
pxut | str | grouped | 2 | TRACT Packed eXtensible User Token. |
limit | str(int) | optional | n/a | Limit on number of messages that the API should return. |
response_type | str | optional | n/a | Either json (default) or text . |
This API allows for fetching the transcripts using either:
-
Group 1: for native Haptik consumers
- business_id
- user_name
- conversation_no
{ "business_id": "1234", "user_name": "ab112468917fgghdebc", "conversation_no": 2 }
- Group 2: for TRACT consumers
- pxut
- conversation_no
{ "pxut": "tw389ysgd._aksdjknsk-545641964-B", "conversation_no": 2 }
Response
A successful request to the API will return a 200
status code with a default JSON response object containing chat data.
JSON response
{
"chat_json": [
{
"text": "Search places to visit{task}",
"sender": "user",
"message_id": 1742,
"timestamp": "06/22/20 07:24:25 AM UTC"
},
{
"text": "TEXT",
"sender": "bot",
"message_id": 1743,
"timestamp": "06/22/20 07:24:26 AM UTC"
}
]
}
Text response
{
"chat_text": "user: Search places to visit{task}\nbot: TEXT\n"
}
Sender values
value | description |
---|---|
bot |
message was sent by the bot |
user |
message was sent by the user |
<agent_name> |
message is sent by an agent, <agent_name> is the name of the agent who sent the message |
Error Response
If there is any error in the Headers or the Request body, then the Error message will be returned in a JSON as shown below:
{
"error_message": "<error_message>"
}
Error messages
Error Message | Details |
---|---|
Invalid business_id | business_id was not a valid string representation of an integer. |
Invalid token | The Authorization token provided is incorrect |
Either the user has not sent a message yet, or the provided user_name-business_id pair is invalid. | Check that the user_name matches the business_id that you are requesting data for, or wait for the user to send a response before sending this request. |
Unable to decode pxut-client_id pair | The TRACT PXUT is mismatched with the client_id provided in the request headers, or one of them is incorrect. Please recheck both. |
Argument group validation: no valid group. | Verify that parameters have been provided to fulfill at least one request group specified above. See response data for more details. |
Argument group validation: invalid group found. | Verify that the parameters provided are of a valid type. See response data for more details. |
An unknown error occurred | Please contact the Haptik team for support. |
FAQ Step Creation APIs for KMS
We have many clients who need FAQ bots. Every time when we want to change the content of these FAQs (Q&As), a new CSV with Step name, Question and Answer in a defined format needs to be uploaded. (Format given below)
We have developed an API that can be integrated with the client KMS(Knowledge Management Systems) via any intermediate layer and every time when data gets changed in KMS, it should call this API to keep data in sync with the Haptik systems.
This API allows you to create/update/delete faq steps via a POST
request to Haptik Platform.
FAQ Step creation process API consists of two parts:
-
Submit the CSV: To handle the large CSV files, this API takes the request data and after validation submit it to the celery worker and returns the
task id
, which executes the task asynchronously. -
Polling API to fetch the status of submitted
task id
Example URL: https://<base-url>/mogambo_api/nodes/faq/create/
1. node_name: Name of the step, step name should be unique
2. Question(User Message): Independent Responses under User Message to detect this FAQ step. Multiple user message for single node can be passed as pipe(|) separated values(refer the sample row in image above)
3. answer(bot response): A step can have single or multiple bot response, to pass multiple bot responses use `<m>` tag as delimiter
Headers
Authorization: Bearer <TOKEN>
client-id: <CLIENT_ID>
Content-Type: multipart/form-data
Request Body
"domain_name": "<Name of the Domain/Bot>",
"csv_file": filename.csv,
Response
A successful request to the API will return a 200
status code with a JSON response object.
{
"success": true,
"body": {
"task_id": "fe139ce5-f4c3-4383-bacb-64a546cb0b6c"
},
"error": "",
"meta": {}
}
- success flag Indicates if the API was a success or failure
- task_id: Job id for the submitted task
Error Response
If there is an error in the Headers or the Request body, then the Error message will be returned in a JSON as shown below:
{
"error_message": "invalid doman"
}
Error Code | Error Message |
---|---|
401 | Unauthorized Access or invalid token |
400 | Invalid or bad request body |
403 | Access Forbidden |
Sample Curl Command to submit CSV file and get job id
curl -X POST \
https://<base-url>/mogambo_api/nodes/faq/create/ \
-H 'authorization: Bearer <token>' \
-H 'client-id: <client-id>' \
-H 'content-type: multipart/form-data;
-F 'domain_name=<domain_name>' \
-F csv_file=@filename.csv
Polling API to fetch submitted task Status
This API allows you to see the status of the submitted task id via a GET
request to Haptik Platform.
Example URL: https://<base-url>/mogambo_api/nodes/faq/create/status/<task_id>/
Headers
Authorization: Bearer <TOKEN>
client-id: <CLIENT_ID>
Response
A successful request to the API will return a 200
status code with a JSON response object.
{
"success": true,
"body": {
"status": "all steps have been created successfully"
},
"error": "",
"meta": {}
}
- success flag Indicates if the API was a success or failure
Sample Curl Command to get the task status
curl -X GET \
https://<base-url>/mogambo_api/nodes/faq/create/status/<task_id>/ \
-H 'authorization: Bearer <TOKEN>' \
-H 'client-id: <CLIENT ID>' \
Possible Statuses:
Error/Exception: shows the exception/error that occurred for the last step and stops the execution
In Progress: Step Creation is in progress
Success: Step has been created successfully
Best Practices
1. Assign Chat to Agent - In some scenarios, where integration response fails or some unknown exception occurs then instead of sending bot break message we can also directly assign the chat to an agent for better user experience.
2.Handle textual content - Every time we want to change the bot's response, a code change is required. To avoid that pain, we can use key-value stores. Any person with zero to little tech knowledge can change bot response from the key-value store (with GUI) by updating the message copy corresponding to that unique message key or ID. This message key can be shared with the developer and fetch the response using that key.
3. HSL's - Haptik defines a superset of UI elements that are available across multiple platforms. These UI elements are then converted to their platform equivalent (js-SDK, android, ios, facebook-messenger, etc..) if they are not available on that specific platform. Eg. Forms are converted to quick replies on the Facebook platform and collected over free form. For more detail read here.
4. Calling the API - There is no limit to the number of calls that you can make to the APIs. However, if Haptik detects a DDOS attack (100-200 calls/sec) then Haptik will block your requests, The recommended rate at which you can call the API is around a max of 100 Calls/minute.