In addition to our standard SMS and Facebook Messenger interfaces, X2 supports custom third party integrations via an embedded web page or popup.
X2 provides two different kinds of user interfaces, for you to choose from:
If your people are using the X2 bot anonymously, then you simply add one line of HTML to your web page. Please reach out to your X2 Health Team member to get your one liner.
If you want to know who is chatting with the X2 bot, then you must use our Add External Person API, which is detailed below. This API will return a unique ID, which you can add to the one liner that your Health Team member provides (see above), to identify the person chatting. Using an API like this requires engineering resources, so please forward this document to your IT/Engineering team, if you need to identify your people.
By default, the X2 web embed and popup interact with people anonymously, in order to protect peoples’ privacy, etc.. However, there are cases where you want to know the identity of the person, so we provide an optional Add External Person API for that purpose.
Standard web embed and popup parameters:
X2’s Add External Person API is used to map a person to a unique X2 Person ID. You can then use that Person ID in the Embed or Popup to identify them when they’re chatting with the X2 bot. You can call this API with an HTTP GET or an HTTP POST.
When you call the Add External Person API for a specific person it will return that person’s X2 Person ID, which you then add to HTML one liner that the X2 Health Team provided.
For example, if the X2 Health Team provided you with this line of HTML:
And if your call to the X2 Add External Person API returned an X2 Person ID of 10f5ddba-c63d-46aa-898a-ec478ba38f24 for Jane Doe, then the full blown URL for Jane Doe to chat with the X2 bot is as follows:
Here's the Add External Person API endpoint:
When calling the Add External Person API, you must specify the following:
HTTP Method: GET or POST
Content-Type: application/json
Additionally, you can also specify the following optional fields:
* If initial_thread_name and ping parameters are not set, then a new person will be created by the API call, but they will not receive a message.
Missing phone number when protocol is sms
res={
'phone': None,
'message': "phone parameter is required"
},
status_code=400
Incorrect auth code
res={
'auth': auth,
'message': "Unauthorized"
},
status_code=401
Incorrect thread name
res={
'thread_name': initial_thread_name,
'message': "Thread name Not Found"
},
status_code=400
Incorrect phone number
res={
'phone': phone,
'message': "Invalid phone number"
},
status_code=400
Note: If you call the Add External Person API with the phone number or external_id of an existing person, then it will simply return that person’s existing X2 Person ID and a 409 code. The ping functionality works regardless of whether or not the person was previously registered with X2.
Existing person with external ID
res={
'existing_person': True,
'person_id': str(person.id_hash) if new_id else str(person.id),
'external_id': str(external_id),
'phone': str(person.phone_number),
'message': "Existing person found already"
},
status_code=409
Existing person
res={
'existing_person': True,
'person_id': str(person.id_hash) if new_id else str(person.id),
'external_id': str(external_id),
'phone': str(person.phone_number),
'message': "Existing person found already"
},
status_code=409
Created new person successfully
res={
'existing_person': False,
'person_id': str(person.id_hash) if new_id else str(person.id),
'external_id': str(external_id),
'phone': str(person.phone_number),
'message': "New person created"
},
status_code=200
The bot will automatically reflect the person’s first name when chatting with the bot. Additionally, you can also reflect the following fields via placeholders in the X2 content:
Add External Person API Field NameBot Content PlaceholderThread (internal use)external_id<<EXTERNAL_ID>>STORE_EXT_IDexternal_username<<EXTERNAL_USERNAME>>STORE_EXT_UNexternal_org<<EXTERNAL_ORG>>
STORE_EXT_ORGexternal_data_1<<ED1>>
external_data_2<<ED2>>
external_data_3<<ED3>>
Previously, X2AI provided a registration endpoint for third party integrations. That third party integration is being replaced by this new one.
Migrating from the legacy registration endpoint to this new Third Party Integration consists of the following changes:
Here is the new URL endpoint for X2’s Add Add External Person API:
Field names that changed:
Fields that have been dropped:
Previously, X2AI provided a person ID which consisted of an integer (e.g. 1943). This ID has now been replaced by a UUID (e.g. 10f5ddba-c63d-46aa-898a-ec478ba38f24 ). In order to assist in this transition a new method /get_new_id will be temporarily available. This method is to be used by clients to update their records in case they keep a copy of our person ID.
Migrating from the legacy person ID consists of the following changes:
For an Initial period of time all of the API functions (/ping_person, /add_external_person, and the PATCH function /external_person/<person_id> ) will provide backwards compatibility with the old ID.
Here is the new URL endpoint for X2’s Get New ID API:
When calling the Get New ID API, you must specify the following:
Once you’ve made the changes above, your API call should look like this:
The client name and auth code are not passed as a param, but rather are encrypted and passed in the API request header as the value of Authorization.
REQUEST HEADER: Required Authentication Header Structure : Authorization=Basic base64Encode(username:password)
Example : Authorization=Basic HFKJOlFTVlo0VzZyu0E3eDU3MGRaejNz
Generates a base64Encode Using client name as the username and auth code as the password. A tool like this can be used to generate base64Encode code: https://www.blitter.se/utils/basic-authentication-header-generator/
The client name and auth code are not passed as a param, but rather are encrypted and passed in the API request header as the value of Authorization.
REQUEST HEADER: Required Authentication Header Structure : Authorization=Basic base64Encode(username:password)
Example : Authorization=Basic HFKJOlFTVlo0VzZyu0E3eDU3MGRaejNz
Generates a base64Encode Using client name as the username and auth code as the password. A tool like this can be used to generate base64Encode code: https://www.blitter.se/utils/basic-authentication-header-generator/
After your people have begun using the X2 bot, you may want to send them to a specific thread in the conversation. This can be achieved by using X2’s Ping Person API. The v2 Ping Person API additionally allows the use of client-defined string placeholders in the message to be pinged.
In order to send someone to a particular thread, we need to know who that person is, so you need to call the Add External Person API (see above) before calling the Ping Person API, for anyone that you want to manage.
Here’s the Ping Person API URL endpoint:
When calling the Ping Person API, you must specify the following parameters:
v2 Ping Person API endpoint:
The required parameters for the v2 endpoint are the same as those listed above, and additionally, you may use the following parameter:
HTTP Method: GET or POST
Content-Type: application/json
REQUEST HEADER:
Required Authentication Header Structure: Authorization=Basic base64Encode(username:password)
Example: Authorization=Basic HFKJOlFTVlo0VzZyu0E3eDU3MGRaejNz
Generates a base64Encode Using client name as the username and auth code as the password
Sample external tool to generate base64Encode code: https://www.blitter.se/utils/basic-authentication-header-generator/
REQUEST example use of placeholders:
{
"messages": [
“<<NAME>> you have an appointment due with a <<APPOINTMENT>> on <<DATE>>"
],
"thread_name": "",
"next_thread_name": "",
"person_id": "",
"is_asynch": false,
"is_auto_next": false,
"placeholders": {
"name": "John",
"appointment": "Doctor",
"date":"June 9th"
}
}
{
"message": "Successfully pinged person",
"person_id": "",
"thread_name": "",
"next_thread_name": ""
}
HTTP STATUS: 200
Here’s an example call with personId of 1234 and thread of good_thread
After your people have begun using the X2 bot, you may want to update their information in our system. This can be achieved by using X2’s External Person API.
In order to update a person’s information, we need to know who that person is, so you need to call the Add External Person API (see above) before calling the External Person API, for anyone that you want to manage.
Here’s the External Person API URL endpoint:
https://prod.x2.ai:8888/external_person/{person_id}
HTTP Method: PATCH
Content-Type: application/json
Request Payload:
{
client: string,
auth: string,
external_id: string,
first_name: string,
last_name: string,
external_username: string,
external_org: string,
phone: string,
external_data_1: string,
external_data_2: string,
external_data_3: string
}
Only client, auth, person_id are mandatory, and the rest are optional details about an existing person to update.
The external_id is expected to be unique and immutable similar to the person_id we generate on our end, it act as a reliable link between the two systems if data need to be reconciled, thus the external_id field cannot be updated.
{
'message': 'No client parameter specified'
}
status code : 400
{
'message': 'Client Not Found'
}
status code : 404
{
'message': 'Unauthorized'
}
status code : 401
{
'message': 'Unknown person with id : {person_id}'
}
status code : 404
{
'message': 'Person is not registered to {client_name}'
}
status code : 404
{
'message': 'External_id already exist'
}
status code : 400
{
'message': 'Invalid phone number {phone}'
}
status code : 400
{
'data': {
'person_id': '{person_id}'
}
}
status code : 200
A private Metabase login allows you to access your bot’s data in Metabase, pull basic queries, and write SQL queries. You are also able to pull from Metabase using the Metabase API to display charts directly in your app.
With Metabase database access, you get access to both the Person Table & Transcript Table, which include the following data columns.
Person Table includes:
Transcript Table includes: