Chat API
Brief guide to Chat API.
- Conventions
- Adapter Management
- List of adapters
- Create an adapter
- Update an adapter
- Delete an adapter
- Chat channels
- List of channels
- Adapter connections
- List of connections
- Create a connection
- Update a connection
- Delete a connection
- Chat API
- Adapter Authentication in Chat API
- Chat API Methods
- Webhooks
- Working with the
wabachannel type - Examples
- Change Log
Conventions
- Personal Account is a web application hosted under
go.callgear.ae. - Operator Workspace is an application that allows employees to handle conversations with customers.
- Adapter is a custom service that uses Chat API methods and webhooks to implement its own operator workspace.
- Chat channel is a connected chat channel in the client account, such as Website Chat, Telegram, or Viber.
- Adapter account is an adapter connection created by the client in the Personal Account.
- Adapter channel is a chat channel connected within the adapter.
- Webhook is an HTTP request that Chat API sends to the adapter when entities change without the adapter directly initiating those changes, for example when a chat is created or a visitor sends a message.
Adapter Management
To get started, you need to register an integration adapter. This can be done through the Personal Account or by sending a request to the main Chat API available at https://cg-dub-omni-chats-logic.callgear.ae/. Only authorized Personal Account users can access this API. To receive an authentication token, you must send a request:
POST https://go.callgear.ae/api/auth/json_rpc?method=login
{
"jsonrpc": "2.0",
"id": "0",
"method": "login",
"params": {
"login": "username",
"password": "password",
"project": "usa"
}
}
Requests to the main Chat API are authenticated using a token passed in the header.
POST https://cg-dub-omni-chats-logic.callgear.ae/v1/
Authorization: Bearer <token>
In the API, the adapter is represented by the Adapter entity.
| Parameter name | Type | Description |
|---|---|---|
id |
int |
Adapter ID |
type |
str |
Unique adapter mnemonic, matches the regular expression ^[a-z0-9_]+$ |
name |
str |
Adapter name |
status |
enum |
Adapter status. Valid values: active, disabled |
supported_channel_types |
enum |
List of channel mnemonics. Valid values: comagic, telegram, auto_ru, avito, realty_yandex, viber, telegram_private, whatsapp, waba, sms, email |
owner |
int |
ID of the adapter owner. Can be null, in which case the adapter is a system adapter |
visibility_status |
enum |
Adapter visibility status; for custom adapters only takes the value private |
login |
str |
Login for adapter authorization |
password |
str |
Password for adapter authorization |
webhook_url |
str |
Address for webhooks from Chat API |
webhook_version |
str |
Webhook version. Available versions: v1, v2; the default version is v2. |
webhook_token |
str |
Chat API authentication token used for webhooks. May not be used together with webhook_auth.This attribute is obsolete and is not recommended for use. |
webhook_auth |
object |
Chat API authentication configuration for webhooks. May not be used together with webhook_token. |
webhook_kwargs |
dict[str, Any] |
An associative array with additional arguments for webhooks. Valid keys: timeout with a value of type float, to control the waiting time for a response from the adapter; an associative array of additional headers headers, of the form {"name": "value"}. |
The webhook_auth object specifies the authentication method for webhooks using a persistent token or login-password pair.
For persistent token authentication, you must set the value of webhook_auth as follows:
{
"type": "Bearer",
"token": "string"
}
In this case, all webhooks will contain a header Authorization: Bearer <token>.
To use a login-password pair, the value of webhook_auth is set as follows:
{
"type": "Basic",
"login": "string",
"password": "string"
}
In this case, all webhooks will contain the header Authorization: Basic <credentials>, where credentials is the Base64-encoded pair <login>:<password>.
List of adapters
GET /v1/integration/adapter
Returns a list of Adapter entities, including both user-created adapters and system adapters. System adapters are identified by the owner attribute set to null. System adapters cannot be modified.
Create an adapter
POST /v1/integration/adapter
{
"type": "string",
"name": "string",
"login": "string",
"password": "string",
"webhook_url": "string",
"webhook_version": "string",
"webhook_token": "string",
"webhook_auth": {
"type": "Bearer",
"token": "string"
},
"supported_channel_types": [
"comagic",
"telegram",
"whatsapp"
]
}
As a result, the Adapter entity is returned.
Update an adapter
PATCH /v1/integration/adapter/{adapter_id}
{
"name": "string",
"login": "string",
"password": "string",
"status": "active",
"webhook_url": "string",
"webhook_version": "string",
"webhook_token": "string",
"webhook_auth": {
"type": "Bearer",
"token": "string"
},
"webhook_kwargs": {},
"supported_channel_types": [
"comagic"
]
}
The method allows you to change the following entity attributes: name, login, password, status, webhook_url, webhook_version, webhook_token, webhook_auth, supported_channel_types.
Delete an adapter
DELETE /v1/integration/adapter/{adapter_id}
The adapter can only be removed when it is not in use.
Chat channels
The Channel entity represents the connected chat channel in the client account.
{
"id": 0,
"type": "comagic",
"name": "string",
"is_removed": true,
"status": "string",
"status_reason": "string"
}
| Parameter name | Type | Description |
|---|---|---|
id |
int |
Channel ID |
type |
enum |
Channel mnemonic |
name |
str |
Channel name |
is_removed |
bool |
Logical delete flag |
status |
enum |
Status |
status_reason |
str |
Reason for status change |
List of channels
GET /v1/integration/channel
Returns a list of entities of type Channel.
Adapter connections
The adapter connection is represented by the Account entity.
{
"name": "string",
"adapter_id": 0,
"channels": [
0
],
"context": {},
"id": 0,
"status": "string"
}
| Parameter name | Type | Description |
|---|---|---|
id |
int |
Account ID |
adapter_id |
int |
Adapter ID |
name |
str |
Account name |
channels |
list[int] |
List of channel IDs |
context |
dict[str, Any] |
Associative array with additional parameters. Valid keys: is_chat_integration_scenario_created with a Boolean value, allows you to control the automatic attachment of the "Forwarding to CRM" scenario for connected channels |
status |
enum |
Connection status. Valid values: active, disabled |
List of connections
GET /v1/integration/account
Returns a list of entities of type Account.
Create a connection
POST /v1/integration/account
{
"name": "string",
"adapter_id": 0,
"channels": [
0
],
"context": {}
}
Update a connection
PATCH /v1/integration/account/{account_id}
{
"name": "string",
"channels": [
0
],
"context": {}
}
The method allows you to change the following entity attributes: name, channels, context.
Delete a connection
DELETE /v1/integration/account/{account_id}
Chat API
The service is available at https://chat-integration-api-cg.callgear.ae/
Entities
Account - represents the connection of the adapter by the client.
{
"id": 0,
"name": "string",
"adapter_id": 0,
"client_id": 0,
"context": {},
"status": "active"
}
| Parameter name | Type | Description |
|---|---|---|
id |
int |
Unique account identifier |
name |
str |
Account name |
adapter_id |
int |
Adapter ID |
client_id |
int |
Internal entity identifier, always takes the value 1 |
context |
dict[str, Any] |
Additional parameters, always contains the key app_id with the identifier of the client that connected the adapter |
status |
enum |
Account status. Possible values: active, disabled |
Channel - represents the connection of the chat channel in the account.
{
"id": 0,
"name": "string",
"type": "comagic",
"account_id": 0,
"context": {},
"status": "active"
}
| Parameter name | Type | Description |
|---|---|---|
id |
int |
Unique channel identifier |
account_id |
int |
Unique account identifier |
name |
str |
Channel name |
type |
enum |
Chat channel mnemonic. Possible values: comagic, telegram, auto_ru, avito, realty_yandex, viber, telegram_private, whatsapp, waba, sms, email |
context |
dict[str, Any] |
Additional options. Always contains the keys app_id with a unique identifier of the client who made the connection, as well as chat_channel_id - a unique identifier of the connected chat channel |
status |
enum |
Channel status. Possible values: active, disabled |
Adapter authentication in Chat API
All requests to the Chat API must contain the Authorization header:
Authorization: Bearer <token>
To obtain a token, the adapter must issue a request:
POST /v1/adapter/login
Content-Type: application/x-www-form-urlencoded
username={adapter_login}&password={adapter_password}
The response will contain the token, type and unix timestamp indicating the end of the token's lifetime:
{
"access_token": "string",
"token_type": "bearer",
"expires_at": 0
}
Once the token lifetime has expired, the authentication procedure must be repeated.
Chat API Methods
Creating a chat
Creating a chat from the adapter is only possible for channels that allow you to start communication first.
This function is supported by the following channel types: whatsapp, waba, telegram_private, sms, email.
POST /v1/adapter/chat
{
"account_id": 0,
"channel_id": 0,
"visitor_phone": "string",
"visitor_email": "string",
"visitor_username": "string",
"operator_id": 0,
"initiator": "operator",
"created_at": "2023-01-01T00:00:00.000Z"
}
Description of the Chat entity:
| Parameter name | Type | Description |
|---|---|---|
account_id |
int |
Account ID |
channel_id |
int |
Channel ID |
operator_id |
int |
Operator ID. The operator must be registered in their Personal Account and have the appropriate privileges |
initiator |
enum |
Initiator mnemonic. Possible values: operator, visitor, autoinvite, chat_channel. Allowed values: operator |
visitor_phone |
Optional[str] |
Phone number of the user with whom the conversation will be conducted (used for channels like whatsapp, waba, sms, telegram_private) |
visitor_email |
Optional[str] |
Email address of the user with whom the conversation will be conducted (used for channel type email) |
visitor_username |
Optional[str] |
Short name of the user with whom the conversation will be conducted, in the format @username (used for channel type telegram_private) |
created_at |
str |
Date and time in ISO 8601 format |
When creating a chat, one of the attributes visitor_phone, visitor_email or visitor_username must be passed, depending on the type of channel in which the communication is initialized.
The response will return the sent entity with the attributes chat_id, which is the request identifier, and visitor_id, which is the identifier of the user with whom the conversation is being conducted. Both parameters should be used later when sending chat messages.
Ending chat
POST /v1/adapter/chat/close
{
"context": {},
"account_id": 0,
"channel_id": 0,
"chat_id": 0,
"operator_id": 0,
"reason": "closed_by_timeout"
}
| Parameter name | Type | Description |
|---|---|---|
| reason | enum |
Reason for termination. Possible values: closed_by_timeout, invite_rejected, closed_by_operator, closed_by_visitor, visitor_banned, external_window_closed, visitor_disconnected, visitor_session_expired, closed_by_scenario. Allowed values: closed_by_operator |
| operator_id | int |
Operator ID. The parameter is optional; it must be passed if closed_by_operator is passed in the value of the reason parameter |
Chat transfer
POST /v1/adapter/chat/transfer
{
"context": {},
"account_id": 0,
"channel_id": 0,
"chat_id": 0,
"from_operator_id": 0,
"to_operator_id": 0
}
| Parameter name | Type | Description |
|---|---|---|
| from_operator_id | int |
Current chat operator ID |
| to_operator_id | int |
Operator ID to whom the chat will be assigned |
Sending message
To send a message to a chat, you need the chat_id. You can get it either from the create-a-chat response or from the new-chat webhook.
POST /v1/adapter/message
{
"account_id": 0,
"channel_id": 0,
"chat_id": 0,
"operator_id": 0,
"reply_to_id": 0,
"text": "string",
"created_at": "2023-01-01T00:00:00.000Z",
"source": "system",
"resource": {
"id": 0,
"token": "string",
"type": "photo",
"name": "string",
"size": 0
}
}
Description of the Message entity:
| Parameter name | Type | Description |
|---|---|---|
account_id |
int |
Account ID |
channel_id |
int |
Channel ID |
chat_id |
int |
Chat ID |
operator_id |
int |
Operator ID |
reply_to_id |
int |
Optional message ID for quoting |
text |
str |
Message text |
created_at |
str |
Date and time in ISO 8601 format |
source |
enum |
Mnemonic of the message sender. Valid values: operator |
resource |
Resource |
Object Resource with a description of the resource (file) attached to the message |
context |
Optional[dict[str, Any]] |
Optional object with additional information |
Adding resource
POST /v1/adapter/resource
Content-Type: multipart/form-data
...
The form must contain the following attributes:
| Parameter name | Type | Description |
|---|---|---|
account_id |
int |
Account ID |
channel_id |
int |
Channel ID |
type |
enum |
Resource type. Possible values: photo, video, audio, voice, document |
file |
bytes |
Transferred file |
The response returns the Resource entity:
| Parameter name | Type | Description |
|---|---|---|
id |
int |
Resource ID |
token |
str |
Resource token |
type |
enum |
Resource type. Possible values: photo, video, audio, voice, document |
name |
str |
File name |
size |
int |
File size in bytes |
Retrieving resource data
GET /v1/adapter/resource/{account_id}/{channel_id}/{resource_id}/{resource_token}/payload
Webhooks
Webhooks are sent to the webhook_url address specified in the adapter settings. webhook_url is used as the base URL: the final address of each webhook is formed by appending a path specific to the event or entity, for example /account or /chat. Authentication data is passed in the Authorization header:
Authorization: {Type} {Credentials}
If the webhook_token attribute is specified when creating an adapter, the Authorization header is formed as follows:
Authorization: Bearer {webhook_token}
Account created
Method: POST
URL: {webhook_url}/account
Available in versions:
v1,v2
{
"id": 0,
"name": "string",
"adapter_id": 0,
"client_id": 0,
"context": {},
"status": "active"
}
Expected response code: 200 or 204.
Account updated
Method: PATCH
URL: {webhook_url}/account/{account_id}
Available in versions:
v1,v2
{
"id": 0,
"name": "string",
"adapter_id": 0,
"client_id": 0,
"context": {},
"status": "active"
}
Expected response code: 200 or 204.
Account deleted
Method: DELETE
URL: {webhook_url}/account/{account_id}
Available in versions:
v1,v2
{
"id": 0,
"name": "string",
"adapter_id": 0,
"client_id": 0,
"context": {},
"status": "active"
}
Expected response code: 200 or 204.
Channel created
Method: POST
URL: {webhook_url}/channel
Available in versions:
v1,v2
{
"id": 0,
"name": "string",
"type": "comagic",
"account_id": 0,
"context": {},
"status": "active"
}
Expected response code: 200 or 204.
Channel updated
Method: PATCH
URL: {webhook_url}/channel/{channel_id}
Available in versions:
v1,v2
{
"id": 0,
"name": "string",
"type": "comagic",
"account_id": 0,
"context": {},
"status": "active"
}
Expected response code: 200 or 204.
Channel deleted
Method: DELETE
URL: {webhook_url}/channel/{channel_id}
Available in versions:
v1,v2
{
"id": 0,
"name": "string",
"type": "comagic",
"account_id": 0,
"context": {},
"status": "active"
}
Expected response code: 200 or 204.
New chat
Method: POST
URL: {webhook_url}/chat
Available in versions:
v1,v2
{
"context": {},
"account_id": 0,
"channel_id": 0,
"chat_id": 0,
"visitor_id": 0,
"visitor_phone": "string",
"operator_id": 0,
"initiator": "operator",
"created_at": "2023-01-01T00:00:00.001Z"
}
Chat updated
Method: PATCH
URL: {webhook_url}/chat
Available in versions:
v2
{
"context": {},
"account_id": 0,
"channel_id": 0,
"chat_id": 0,
"operator_id": 0
}
Ending chat
Method: POST
URL: {webhook_url}/chat/close
Available in versions:
v1,v2
{
"context": {},
"account_id": 0,
"channel_id": 0,
"chat_id": 0,
"operator_id": 0,
"reason": "closed_by_timeout"
}
Expected response code: 200 or 204. The operator_id parameter is optional.
Chat assigned to an operator
Method: POST
URL: {webhook_url}/chat/operator
Available in versions:
v1
{
"context": {},
"account_id": 0,
"channel_id": 0,
"chat_id": 0,
"operator_id": 0
}
New message
Method: POST
URL: {webhook_url}/message
Available in versions:
v1,v2
{
"context": {},
"account_id": 0,
"channel_id": 0,
"id": 0,
"chat_id": 0,
"source": "system",
"operator_id": 0,
"reply_to_id": 0,
"text": "string",
"created_at": "2023-01-01T00:00:00.001Z",
"status": "accepted",
"resource": {
"id": 0,
"token": "string",
"type": "photo",
"name": "string",
"size": 0
},
"system_message_mnemonic": "string"
}
The status parameter can take the following values: accepted, delivered, read, sent, error.
Message updated
Method: POST
URL: {webhook_url}/message
Available in versions:
v2
{
"context": {},
"account_id": 0,
"channel_id": 0,
"id": 0,
"chat_id": 0,
"text": "string",
"resource": {
"id": 0,
"token": "string",
"type": "photo",
"name": "string",
"size": 0
}
}
Message status updated
Method: POST
URL: {webhook_url}/message/status
Available in versions:
v1,v2
{
"context": {},
"account_id": 0,
"channel_id": 0,
"chat_id": 0,
"message_id": 0,
"status": "accepted"
}
Visitor information updated
Method: POST
URL: {webhook_url}/visitor/card
Available in versions:
v1,v2
{
"context": {},
"account_id": 0,
"channel_id": 0,
"visitor_id": 0,
"visitor_card": {}
}
Description of the visitor_card object:
| Parameter name | Type | Description |
|---|---|---|
name |
str |
Name |
company |
str |
Company |
comment |
str |
Comment |
phones |
list[str] |
List of phone numbers |
emails |
list[str] |
Email list |
Migration from webhook version v1 to v2
The main differences between v2 and v1 are:
- instead of the chat assigned to an operator webhook, the chat updated webhook is used;
- the message updated webhook was added.
Working with the waba channel type
The waba channel type has two key features: outgoing messages can only be initiated through predefined templates, and a conversation can continue only within the time window that opens after the visitor replies to the operator.
Information about the templates available for use (as well as their changes) is passed in webhooks associated with the channel, in the context["message_templates"] attribute of type list[MessageTemplate].
To fully support waba templates, the adapter must implement webhook version v2.
Structure of the MessageTemplate message template:
| Parameter name | Type | Description |
|---|---|---|
id |
int |
Template ID |
name |
str |
Template name |
content |
MessageTemplateContent |
Template content |
createdAt |
datetime |
Date and time the template was created |
Content structure of template MessageTemplateContent:
| Parameter name | Type | Description |
|---|---|---|
text |
str |
Message text |
header |
MessageTemplateContentHeader |
Heading |
footer |
MessageTemplateContentFooter |
Footnote |
keyboard |
MessageTemplateContentKeyboard |
Menu buttons |
MessageTemplateContentHeader message header structure:
| Parameter name | Type | Description |
|---|---|---|
text |
Optional[str] |
Title text |
headerType |
Optional[enum] |
Header type. Valid values: TEXT, VIDEO, IMAGE, DOCUMENT |
headerExampleMediaUrl |
Optional[str] |
Footnote structure of message MessageTemplateContentFooter:
| Parameter name | Type | Description |
|---|---|---|
text |
Optional[str] |
Footnote text |
Structure of the MessageTemplateContentKeyboard object:
| Parameter name | Type | Description |
|---|---|---|
rows |
list[MessageTemplateContentKeyboardRow] |
List of objects of type MessageTemplateContentKeyboardRow |
Structure of the MessageTemplateContentKeyboardRow object:
| Parameter name | Type | Description |
|---|---|---|
buttons |
list[MessageTemplateContentButton] |
List of objects of type MessageTemplateContentButton |
Structure of the MessageTemplateContentButton object:
| Parameter name | Type | Description |
|---|---|---|
text |
str |
Button text |
buttonType |
enum |
Button type. Valid values: QUICK_REPLY, URL, PHONE |
payload |
str |
Answer text. Only applicable for button type QUICK_REPLY |
url |
str |
Link. Only applicable for button type URL |
phone |
str |
Phone number. Only applicable for button type PHONE |
Sending a message using a template
To send a message with a template, use the sending a message method. The template is passed in the context[template] attribute in the following format:
| Parameter name | Type | Description |
|---|---|---|
id |
int |
Template ID |
text |
str |
Message text |
header |
MessageTemplateContentHeader |
Heading |
footer |
MessageTemplateContentFooter |
Footnote |
keyboard |
MessageTemplateContentKeyboard |
Menu buttons |
Time window information is passed in the new message and message updated webhooks in the context["conversation_frame_ts"] attribute of type int.
The attribute value is a unix timestamp indicating the end time of the time window. If the attribute or its value is missing, then the time window is considered to be closed.
Examples
This example registers an adapter, connects a channel of type whatsapp, creates a chat and sends a message.
Setting up
Obtaining authentication token
Request:
POST https://go.callgear.ae/api/auth/json_rpc?method=login
{
"jsonrpc": "2.0",
"id": "1742467134",
"method": "login",
"params": {
"login": "my_login",
"password": "my_password",
"project": "usa"
}
}
Answer:
{
"error" : null,
"id" : "U7-r8Ld5BUakw2OP337Xy",
"jsonrpc" : "2.0",
"result" : {
"is_2fa_enabled" : false,
"jwt" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
"refresh" : "69cc054cf22042d38f39bd06bc4d7707"
}
}
The resulting value result["jwt"] is used as a token.
Creating the adapter
Request:
POST https://cg-dub-omni-chats-logic.callgear.ae/v1/integration/adapter
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
{
"type": "custom_solutions_llc_adapter",
"name": "Custom Solutions LLC Chat Adapter",
"login": "my_very_secret_and_unique_login",
"password": "something_stronger_than_just_1234567890",
"webhook_url": "https://webhook.my-custom-solutions.com/chat-integration",
"webhook_auth": {
"type": "Basic",
"login": "my_webhook_basic_login",
"password": "my_webhook_basic_password"
},
"supported_channel_types": [
"comagic",
"whatsapp"
]
}
Answer:
{
"id": 322,
"type": "custom_solutions_llc_adapter",
"name": "Custom Solutions LLC Chat Adapter",
"status": "active",
"supported_channel_types": [
"comagic",
"whatsapp"
],
"owner": 4735,
"visibility_status": "private",
"login": "my_very_secret_and_unique_login",
"webhook_url": "https://webhook.my-custom-solutions.com/chat-integration",
"webhook_kwargs": {}
}
Getting a list of chat channels connected to your account
Request:
GET https://cg-dub-omni-chats-logic.callgear.ae/v1/integration/channel
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Answer:
[
{
"id": 740805,
"channel_id": 28910,
"type": "whatsapp",
"name": "Main Whatsapp Channel",
"is_active": true,
"is_removed": false,
"status": "active",
"status_reason": ""
}
]
Connecting a channel
To connect the channel, the availability of the web server specified in webhook_url when creating the adapter is mandatory.
The value adapter_id is the adapter identifier (id) obtained at the "creating an adapter" step.
The list channels indicates the channel identifiers (id) that need to be connected. In the example, the identifier 740805 is used, corresponding to the channel called "Main Whatsapp Channel" from the previous step.
Request:
POST https://cg-dub-omni-chats-logic.callgear.ae/v1/integration/account
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
{
"name": "Custom Solutions LLC Chat Adapter Integration",
"adapter_id": 322,
"channels": [740805],
"context": {}
}
Answer:
{
"name": "Custom Solutions LLC Chat Adapter Integration",
"adapter_id": 322,
"channels": [740805],
"context": {},
"id": 286,
"status": "active"
}
POST https://webhook.my-custom-solutions.com/chat-integration/account
Authorization: Basic bXlfd2ViaG9va19iYXNpY19sb2dpbjpteV93ZWJob29rX2Jhc2ljX3Bhc3N3b3Jk
{
"id": 286,
"name": "Custom Solutions LLC Chat Adapter Integration",
"adapter_id": 322,
"client_id": 1,
"context": {"app_id": 4735},
"status": "active"
}
POST https://webhook.my-custom-solutions.com/chat-integration/channel
Authorization: Basic bXlfd2ViaG9va19iYXNpY19sb2dpbjpteV93ZWJob29rX2Jhc2ljX3Bhc3N3b3Jk
{
"id": 3580,
"name": "Main Whatsapp Channel",
"type": "whatsapp",
"account_id": 286,
"context": {"app_id": 4735, "chat_channel_id": 740805},
"status": "active"
}
Using the adapter
Obtaining an adapter token
Request:
POST https://chat-integration-api-cg.callgear.ae/v1/adapter/login
Content-Type: application/x-www-form-urlencoded
username=my_very_secret_and_unique_login&password=something_stronger_than_just_1234567890
Answer:
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...RMagvgqDBSD8xlr18E8M-8vNazAZwN_01YZopaq7-zg",
"token_type": "bearer",
"expires_at": 1742541741
}
For all subsequent Chat API requests, pass the received access_token in the Authorization header.
Creating a chat
Request:
POST https://chat-integration-api-cg.callgear.ae/v1/adapter/chat
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
{
"account_id": 286,
"channel_id": 3580,
"visitor_phone": "74959268686",
"operator_id": 367852,
"initiator": "operator",
"created_at": "2025-03-21T05:00:00.000+00:00"
}
In this and subsequent requests, account_id uses the account ID returned by the account-created webhook, and channel_id uses the channel ID returned by the channel-created webhook.
The employee ID (operator_id) was obtained from the Data API using the get.employees method.
Answer:
{
"context": {},
"account_id": 286,
"channel_id": 3580,
"chat_id": 199304420,
"visitor_id": 9012381597,
"visitor_phone": "74959268686",
"visitor_email": null,
"visitor_username": null,
"operator_id": 367852,
"initiator": "operator",
"created_at": "2025-03-21T05:00:00.248137+00:00"
}
Webhook with a system message about the start of the chat:
POST https://webhook.my-custom-solutions.com/chat-integration/message
Authorization: Basic bXlfd2ViaG9va19iYXNpY19sb2dpbjpteV93ZWJob29rX2Jhc2ljX3Bhc3N3b3Jk
{
"context": {"app_id": 4735, "chat_channel_id": 740805},
"account_id": 286,
"channel_id": 3580,
"id": 623010892,
"chat_id": 199304420,
"source": "system",
"operator_id": null,
"reply_to_id": null,
"text": "Chat started by operator Marina",
"created_at": "2025-03-21T05:00:00.248137+00:00",
"status": "sent",
"resource": null,
"system_message_mnemonic": "chat_started"
}
Sending a message to a chat
Request:
POST https://chat-integration-api-cg.callgear.ae/v1/adapter/message
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
{
"account_id": 286,
"channel_id": 3580,
"chat_id": 199304420,
"source": "operator",
"operator_id": 367852,
"text": "Message from the operator",
"created_at": "2025-03-21T05:00:01+00:00"
}
Use the chat_id returned by the create-a-chat request.
Answer:
{
"context": null,
"account_id": 286,
"channel_id": 3580,
"id": 623010897,
"chat_id": 199304420,
"source": "operator",
"operator_id": 367852,
"reply_to_id": null,
"text": "Message from the operator",
"created_at": "2025-03-21T05:00:01+00:00",
"status": null,
"resource": null,
"system_message_mnemonic": null
}
Webhook with message delivery status:
POST https://webhook.my-custom-solutions.com/chat-integration/message/status
Authorization: Basic bXlfd2ViaG9va19iYXNpY19sb2dpbjpteV93ZWJob29rX2Jhc2ljX3Bhc3N3b3Jk
{
"context": {"app_id": 4735, "chat_channel_id": 740805},
"account_id": 286,
"channel_id": 3580,
"chat_id": 199304420,
"message_id": 623010897,
"status": "delivered"
}
Change Log
1.10.0 (2025-05-15)
- Information about channels has been clarified, supporting initialization of communication.
1.9.0 (2025-04-11)
- The documentation on creating the adapter has been clarified (indication of
webhook_version).
1.8.0 (2025-03-20)
- Added section "Examples".
1.7.0 (2024-12-09)
- Added information about the new version of webhooks
v2. - The list of channel types that the adapter can use has been expanded.
- Added information about working with channel type
waba.
1.6.0 (2024-10-01)
- Added information about the new attribute of the
webhook_authadapter.
1.5.1 (2024-09-26)
- Added information about webhooks in the Conventions section.
1.5.0 (2024-04-11)
- Added information about versioning webhooks.
- Added implementation of the chat end method.
- Added a new method for chat transfer.
1.4.0 (2023-09-18)
Added information about obtaining an authentication token (login to your Personal Account).
1.3.0 (2023-09-18)
The redundant attribute visitor_id has been removed from the new message event.
1.2.0 (2023-09-14)
The redundant attributes app_id and site_id have been removed from all events.
1.1.0 (2023-09-13)
Updated authentication information.
1.0.0 (2023-09-12)
Initial version.