Chatbox user API

Allow your chatbot to claim and close messages

Lexer's Chatbot User API enables your chatbot to close messages from your Respond Inbox while it has control of a conversation on Facebook or Twitter. It's designed around the principle that your chatbot is another member of your team with limited permission to claim messages, close messages, and echo responses that it has published.

How it works

As your chatbot is handling the conversation with a customer, it constantly hits the Lexer API to 1) Claim ownership and close messages from the inbox, and 2) Echo responses it has published. Claiming ownership and closing messages will remove them from the inbox so your team are not double handling messages. Echoing responses will update the conversation history to show your team members that particular replies have been sent from the chatbot, and not members of your team.

If your chatbot is unable to resolve the customer's query, and needs to hand over to an agent, it can release the conversation to show subsequent messages in the Lexer Respond inbox. To do this, the chatbot simply stops calling the Claim and close API endpoint, and all new messages from the customer appear in the Respond inbox alongside other conversations for your team to pick up.

Authentication

To begin, you must create a new Bot User in Manage > Team > Our Team. Once created, you can click on the bot user in your team list to open the user's details and view examples of the bots API calls, as well as its unique API token. All requests to the Chatbot API are authenticated with an API token that must be sent via the Auth-Api-Token HTTP header.

Action 1: Claim and close

Our first API endpoint is to be used for all messages your chatbot receives while handling the conversation with your customer. The claim and close action is removing the messages from the Respond workflow. To handover a conversation to your team, the chatbot should be configured to stop calling the API. All subsequent messages will then enter the Inbox queue and a Customer Service Agent will pick it up.

Example

curl -H "Content-Type: application/json" -H "Auth-Api-Token: <ACCESS_TOKEN>" -X POST https://hub.lexer.io/api/clients/<CLIENT_ID>/bots/objects/claim -d '
{
    "object_id":"<OBJECT_ID>",
    "published_at":"<CREATED_TIME>",
    "source": "facebook",
    "state": "closed",
    "account_id": "<FACEBOOK_PAGE_ID>"
}'

Action 2: Echo response

Our second API endpoint is to be used for all messages that the chatbot sends to a customer. It is indicating that this particular response has been generated by the chatbot and will inform the Customer Service Agent that it was an automated response.

Example

curl -H "Content-Type: application/json" -H "Auth-Api-Token: <ACCESS_TOKEN>" -X POST https://hub.lexer.io/api/clients/<CLIENT_ID>/bots/objects/echo -d '

{
    "object_id":"<OBJECT_ID>",
    "published_at":"<CREATED_TIME>",
    "source": "facebook",
    "account_id": "<FACEBOOK_PAGE_ID>"
}'

Facebook API Example

Let’s deconstruct a webhook message received from Facebook to understand which fields are required to interact with the Chatbot API.

{
  "Sender":{
    "id":"USER_ID"
  },
  "Recipient":{
    "id":"PAGE_ID"
  },
  "Timestamp":1458692752478,
  "Message":{
    "Mid":"mid.1457764197618:41d102a3e1ae206a38",
    "text":"hello, world!",
    "quick_reply": {
      "payload": "DEVELOPER_DEFINED_PAYLOAD"
    }
  }
}

The parameters expected by the Lexer API could be retrieved from the message as per the table below:

Lexer API Parameter Messenger API Type Comments
object_id message.mid String ID for the message being actioned.
published_at timestamp String or integer Can be an epoch eg. 1458692752478 or an ISO8601 date eg. “2017-08-01t05:29:44Z”
source facebook String Always “facebook”
state closed String Always “closed”
account_id recipient.id String Facebook page ID
client_id n/a Integer ID of the Lexer client, found with the access token associated with the Bot User in Lexer Hub. Must be used in the URL.

API Response Codes

List of response codes, the body returned, and their description.

Status Body Description
201 {“status”:”ok”} Request was successfully accepted by Lexer.
400 {“status”:”400 Invalid Account”,”error”:”Cannot find an integrated account: 12345”} Integrated Facebook page cannot be found within Lexer.
500 Scary HTML response Invalid JSON or invalid parameter.
500 {“error”:”object_id is missing”} Required field is missing.
500 {“error:”source does not have a valid value”} Source value is not “facebook”.
500 {“error”:”state does not have a valid value”} State value s not set to “closed”.
Updated:
October 14, 2022
Did this page help you?
Thank you! Your feedback has been received!
Oops! Something went wrong while submitting the form, for assistance please contact support@lexer.io
Welcome to Lexer!
Fundamentals
Getting started
Our glossary
Fundamentals
Getting started
Integrations
Fundamentals
Setup
My account
Fundamentals
Setup
Manage team
Fundamentals
Setup
Group permissions
Fundamentals
Setup
Classifications
Fundamentals
Setup
Out of the box segments
Fundamentals
Setup
Browser guide
Fundamentals
Security
Corporate networks
Fundamentals
Security
Emergency contact
Fundamentals
Security
Multi-factor authentication
Fundamentals
Security
Single sign-on
Fundamentals
Security
Trust and compliance
Fundamentals
Security
Lexer's Identity Resolution
Fundamentals
Identity Resolution
Troubleshooting tech issues
Fundamentals
Troubleshooting
Error code: 503 Service Unavailable
Fundamentals
Troubleshooting
Error code: 401 Unauthorized
Fundamentals
Troubleshooting
Error code: 403 Forbidden
Fundamentals
Troubleshooting
Troubleshooting Activate
Fundamentals
Troubleshooting
Troubleshooting Respond
Fundamentals
Troubleshooting
Help! My data is missing from the Hub
Fundamentals
Troubleshooting
Understanding APIs at Lexer
Data
Data Onboarding
Providing JSON data to Lexer
Data
Data Onboarding
Providing CSV data to Lexer
Data
Data Onboarding
Upload using SFTP
Data
Data Onboarding
Upload using S3
Data
Data Onboarding
Lexer data specification
Data
Lexer Data Specification
Customer data specification
Data
Lexer Data Specification
Commerce data specification
Data
Lexer Data Specification
Marketing data specification
Data
Lexer Data Specification
Compliance data specification
Data
Lexer Data Specification
Data Formatting and Validation
Data
Getting Started with APIs
Authentication and API token creation
Data
Getting Started with APIs
Rate Limits
Data
Getting Started with APIs
Response codes and common errors
Data
Getting Started with APIs
Product imagery
Data
Getting Started with APIs
Currency conversion
Data
Getting Started with APIs
Lexer’s APIs overview
Data
Lexer’s APIs
Dataset management in the Hub
Data
Dataset management
Chatbox user API
Data
Lexer’s APIs
Activity API
Data
Lexer’s APIs
Visualize API
Hidden from nav
Profile Read API
Data
Lexer’s APIs
Lexer Javascript Tag basics
Data
Lexer Javascript Tag
Lexer Javascript Tag technical guide
Data
Lexer Javascript Tag
Lexer Javascript Tag use cases
Data
Lexer Javascript Tag
dataLayer configuration: Shopify
Data
Lexer Javascript Tag
Customer segment CSV export
Data
Data off-boarding
Export to CSV
Data
Data off-boarding
Data in Lexer's CDXP
Understand
Customer Data
Lexer's attributes
Understand
Customer Data
Attribute value types
Understand
Customer Data
Data source - CRM
Understand
Customer Data
Data source - Transactions
Understand
Customer Data
Data source - Email
Understand
Customer Data
Partner data - Experian
Understand
Customer Data
Partner data - Mastercard
Understand
Customer Data
Partner data - Roy Morgan
Understand
Customer Data
GDPR and CCPA requests
Understand
Customer Data
Upload data files
Understand
Customer Data
File upload API
Understand
Customer Data
Data provision and schemas
Understand
Customer Data
Segment overview
Understand
Segment
Creating segments
Understand
Segment
Smart Search
Understand
Segment
Export attribute results
Understand
Segment
Contact a customer
Understand
Segment
Fixing a disabled segment
Understand
Segment
Profile tab
Understand
Segment
Compare segments
Understand
Compare
Compare attributes
Understand
Compare
Activate overview
Engage
Activate
Ongoing activations
Engage
Activate
Audience splits
Engage
Activate
A/B splits
Engage
Activate
Control group splits
Engage
Activate
Inbox filtering
Engage
Respond
Ignored Senders
Engage
Respond
Forms for service
Engage
Respond
Workflow states
Engage
Respond
Bulk changes
Engage
Respond
Scheduled replies
Engage
Respond
Message templates
Engage
Respond
Customer profiles
Engage
Respond
Grouped messages
Engage
Respond
Automation rules
Engage
Respond
Redact messages
Engage
Respond
Track overview
Measure
Track
Activity overview
Measure
Activity
Team report
Measure
Activity
Cases report
Measure
Activity
Listen overview
Measure
Listen
Searching in Listen
Measure
Listen
Tier filters
Measure
Listen
Boolean search
Measure
Listen
Saved dives
Measure
Listen
Email notifications
Measure
Listen
Twitter data
Measure
Listen
Facebook data
Measure
Listen
Instagram data
Measure
Listen
Visualize overview
Measure
Visualize
Curate feed
Measure
Visualize
Report overview
Measure
Report