Chat API
Agreements
The following agreements are accepted when using Chat API:
- Personal Account – A web application located in the domain go.callgear.com or go.calglear.ae.
- Operator’s Workspace – An application that allows employees to engage in conversations with customers.
- Adapter – A user service that implements a custom version of the Operator’s Workspace using Chat API method requests and webhooks processing.
- Chat Channel – A connected chat channel (Website Chat, WhatsApp, Instagram, Facebook, Telegram etc.) in the client’s account.
- Adapter Account – A client’s integration of an adapter in the Personal Account.
- Adapter Channel – A connection of a chat channel within the adapter.
Webhook – An HTTP request that Chat API sends to the adapter when an entity changes without direct participation from the adapter itself (e.g., chat creation, message sent by a visitor, system messages, etc.).
Manage Adapters
To begin, you need to register an integration adapter. This can be done by sending a request to the primary Chat API, available at:
https://chats-cg-logic.callgear.ae (UAE) or https://chats-cg-logic.callgear.com (international; from this point forward, all links in the document will default to the .ae
domain. If you are outside the UAE and your Callgear account uses the .com
domain, please replace .ae
with .com
wherever necessary). Only authorized users of the Personal Account have access to the API. To obtain an authentication token, you need to 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"
}
}
All requests to the main Chat API must be authenticated using a token, which is passed in the request header.
POST https://chats-cg-logic.callgear.ae/v1/
Authorization: Bearer
In the API, adapters are represented by the Adapter
entity.
json
{
"id": 0,
"type": "string",
"name": "string",
"status": "active",
"supportedchanneltypes": [
"comagic",
"telegram",
"facebook",
"viber",
"telegram_private",
"whatsapp",
"instagram",
"waba",
"sms"
],
"owner": 0,
"visibility_status": "private",
"login": "string",
"password": "string",
"webhook_url": "string",
"webhook_version": "string",
"webhook_token": "string",
"webhook_auth": {
"type": "Bearer",
"token": "string"
},
"webhook_kwargs": {}
}
Parameter Name | Type | Description |
id | int | Adapter identifier |
type | str | Unique mnemonic for the adapter. Must match the regular expression ^[a-z0-9_]+$ . |
name | str | Adapter name |
status | enum | Adapter status. Allowed values: active , disabled . |
supportedchanneltypes | enum | List of channel mnemonics. Allowed values: comagic , telegram , facebook , viber , telegram_private , whatsapp , instagram . |
owner | int | Adapter owner’s identifier. Can be null ; if so, the adapter is considered system-level. |
visibility_status | enum | Adapter visibility status. For user adapters, only the value private is allowed. |
login | str | Login for adapter authentication |
password | str | Password for adapter authentication |
webhook_url | str | URL for webhooks from the Chat API |
webhook_version | str | Webhooks version. Available versions: v1 , v2 ; by default, version v1 is used. |
webhooktoken | str | Token for Chat API authentication used for webhooks. Cannot be used in conjunction with webhookauth . |
webhookauth | object | Chat API authentication configuration for webhooks. Cannot be used in conjunction with webhooktoken . |
webhook_kwargs | dict[str, Any] | Associative array with additional arguments for webhooks. Allowed keys: timeout (a float) to control the adapter’s response wait time; an associative array of additional headers headers in the form {"name": "value"} . |
The webhook_auth
object defines the authentication method for webhook requests. It allows authentication using a token:
json
{
"type": "Bearer",
"token": "string"
}
Alternatively, you can also use login-password pair:
json
{
"type": "Basic",
"login": "string",
"password": "string"
}
Adapters List
GET /v1/integration/adapter
Returns a list of Adapter
entities, including both user-added adapters and system adapters. System adapters are distinguished by having a null
value in the owner
attribute. System adapters cannot be modified.
Create Adapter
POST /v1/integration/adapter
{
"type": "string",
"name": "string",
"login": "string",
"password": "string",
"webhook_url": "string",
"webhook_token": "string",
"webhook_auth": {
"type": "Bearer",
"token": "string"
},
"supportedchanneltypes": [
"comagic",
"telegram",
"whatsapp"
]
}
Returns the created Adapter
entity.
Update Adapter
PATCH /v1/integration/adapter/{adapter_id}
{
"name": "string",
"login": "string",
"password": "string",
"status": "active",
"webhook_url": "string",
"webhook_token": "string",
"webhook_auth": {
"type": "Bearer",
"token": "string"
},
"webhook_kwargs": {},
"supportedchanneltypes": [
"comagic"
]
}
Allows updating the following attributes: name
, login
, password
, status
, webhookurl
, webhooktoken
, webhookauth
, supportedchannel_types
.
Delete Adapter
DELETE /v1/integration/adapter/{adapter_id}
An adapter can only be deleted if it is not in use.
Chat Channels
Entity channel
represents a connected chat channel within a client account.
json
{
"id": 0,
"type": "comagic",
"name": "string",
"is_removed": true,
"status": "string",
"status_reason": "string"
}
Parameter | Type | Description |
id |
int | Channel identifier |
type |
enum | Channel mnemonic |
name |
str | Channel name |
is_removed |
bool | Logical deletion flag |
status |
enum | Channel status |
status_reason |
str | Reason for status change |
Channels List
GET /v1/integration/channel
Returns a list of Channel
entities.
Connect Adapter
The adapter connection is represented by the Account
entity.
json
{
"name": "string",
"adapter_id": 0,
"channels": [
0
],
"context": {},
"id": 0,
"status": "string"
}
Parameter | Type | Description |
id |
int | Account identifier |
adapter_id |
int | Adapter identifier |
name |
string | Account name |
channels |
list[int] | List of channel IDs |
context |
dict[str, Any] | Additional parameters. Includes ischatintegrationscenariocreated (bool) for automatic CRM forwarding scenario attachment |
status |
enum | Connection status. Possible values: active , disabled |
Connections List
GET /v1/integration/account
Returns a list of Account
entities.
Create Connection
POST /v1/integration/account
{
"name": "string",
"adapter_id": 0,
"channels": [
0
],
"context": {}
}
Update Connection
PATCH /v1/integration/account/{account_id}
{
"name": "string",
"channels": [
0
],
"context": {}
}
Allows updating the following attributes: name
, channels
, context
.
Delete 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 adapter connection by a client.
json
{
"id": 0,
"name": "string",
"adapter_id": 0,
"client_id": 0,
"context": {},
"status": "active"
}
Parameter | Type | Description |
id |
int | Unique account identifier |
name |
str | Account name |
adapter_id |
int | Adapter identifier |
client_id |
int | Internal entity identifier, always 1 |
context |
dict[str, Any] | Additional parameters, always contains the key app_id identifying the client who connected the adapter |
status |
enum | Adapter status. Possible values: active , disabled |
Channel
represents the chat channel connection within an account.
json
{
"id": 0,
"name": "string",
"type": "comagic",
"account_id": 0,
"context": {},
"status": "active"
}
Parameter | 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 , facebook , viber , telegram_private , whatsapp , instagram |
context |
dict[str, Any] | Additional parameters, always containing appid (client identifier) and chatchannel_id (unique chat channel identifier) |
status |
enum | Channel status. Possible values: active , disabled |
Adapter Authentication in Chat API
All requests to the Chat API must include the Authorization
header:
Authorization: Bearer
To obtain a token, the adapter must make the following request:
POST /v1/adapter/login
Content-Type: application/x-www-form-urlencodedusername={adapterlogin}&password={adapterpassword}
The response will contain the token, type, and a Unix timestamp indicating the token’s expiration time.
json
{
"access_token": "string",
"token_type": "bearer",
"expires_at": 0
}
Once the token expires, authentication must be repeated.
Chat API Methods
Create Chat
Creating a chat from an adapter is only possible for channels that allow initiating communication first. Currently, only chat channels with the mnemonic whatsapp
support this functionality.
POST /v1/adapter/chat
{
"account_id": 0,
"channel_id": 0,
"visitor_phone": "string",
"operator_id": 0,
"initiator": "operator",
"created_at": "2023-01-01T00:00:00.000Z"
}
Chat
Entity Description
Parameter | Type | Description |
account_id |
int | Account identifier |
channel_id |
int | Channel identifier |
operator_id |
int | Operator identifier. The operator must be registered in the personal account and have the necessary privileges. |
initiator |
enum | Initiator mnemonic. Possible values: operator , visitor , autoinvite , chat_channel . Allowed values: operator . |
visitor_phone |
str | Phone number of the user the conversation will be conducted with. |
created_at |
str | Date and time in ISO 8601 format. |
The response will contain the sent entity with the attributes:
chat_id
– Identifier of the conversation.visitor_id
– Identifier of the user with whom the conversation is conducted.
Both parameters must be used for sending messages in the chat.
Finish Chat
POST /v1/adapter/chat/close
{
"context": {},
"account_id": 0,
"channel_id": 0,
"chat_id": 0,
"operator_id": 0,
"reason": "closedbytimeout"
}
Parameter | Type | Description |
reason |
enum | Reason for chat closure. Possible values: closedbytimeout , inviterejected , closedbyoperator , closedbyvisitor , visitorbanned , externalwindowclosed , visitordisconnected , visitorsessionexpired , closedbyscenario . Allowed values: closedby_operator . |
operatorid |
int | Operator identifier. This parameter is optional and must be provided if reason is set to closedby_operator . |
Transfer Chat
POST /v1/adapter/chat/transfer
{
"context": {},
"account_id": 0,
"channel_id": 0,
"chat_id": 0,
"fromoperatorid": 0,
"tooperatorid": 0
}
Parameter | Type | Description |
fromoperatorid |
int | Identifier of the current chat operator. |
tooperatorid |
int | Identifier of the operator to whom the chat will be assigned. |
Send Message
To send a message in a chat, you need to know the chat identifier chat_id
, which can be obtained either when creating the chat or from a webhook received upon chat creation.
POST /v1/adapter/message
{
"account_id": 0,
"channel_id": 0,
"chat_id": 0,
"operator_id": 0,
"replytoid": 0,
"text": "string",
"created_at": "2023-01-01T00:00:00.000Z",
"source": "system",
"resource": {
"id": 0,
"token": "string",
"type": "photo",
"name": "string",
"size": 0
}
}
Message
Entity Description
Parameter | Type | Description |
account_id |
int | Account identifier. |
channel_id |
int | Channel identifier. |
chat_id |
int | Chat identifier. |
operator_id |
int | Operator identifier. |
replytoid |
int | Optional identifier of the message being quoted. |
text |
str | Message text. |
created_at |
str | Date and time in ISO 8601 format. |
source |
enum | Message sender mnemonic. Allowed value: operator . |
resource |
Resource | Resource object describing an attached file. |
context |
Optional[dict[str, Any]] | Optional object containing additional information. |
Add Resource
POST /v1/adapter/resource
Content-Type: multipart/form-data
The form must contain the following attributes:
Parameter | Type | Description |
account_id |
int | Account identifier. |
channel_id |
int | Channel identifier. |
type |
enum | Resource type. Possible values: photo , video , audio , voice , document . |
file |
bytes | The file to be uploaded. |
The response returns the Resource
entity.
Parameter | Type | Description |
id |
int | Resource identifier. |
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. |
The response will contain the requested resource data.
Get Resource Data
GET /v1/adapter/resource/{accountid}/{channelid}/{resourceid}/{resourcetoken}/payload
Webhooks
Webhooks are sent in response to interactions with chat entities to the webhook_url
specified in the adapter configuration. Authentication data is included in the Authorization
header.
Authorization: {Type} {Credentials}
In cases where the webhook_token
attribute is specified when creating the adapter, the Authorization
header is formed as follows:
Authorization: Bearer {webhook_token}
Create Account
Available in versions: v1, v2
POST /account
{
"id": 0,
"name": "string",
"adapter_id": 0,
"client_id": 0,
"context": {},
"status": "active"
}
Update Account
Available in versions: v1, v2
PATCH /account/{account_id}
{
"id": 0,
"name": "string",
"adapter_id": 0,
"client_id": 0,
"context": {},
"status": "active"
}
Delete Account
Available in versions: v1, v2
DELETE /account/{account_id}
{
"id": 0,
"name": "string",
"adapter_id": 0,
"client_id": 0,
"context": {},
"status": "active"
}
Create Channel
Available in versions: v1, v2
POST /channel
{
"id": 0,
"name": "string",
"type": "comagic",
"account_id": 0,
"context": {},
"status": "active"
}
Update Channel
Available in versions: v1, v2
PATCH /channel/{channel_id}
{
"id": 0,
"name": "string",
"type": "comagic",
"account_id": 0,
"context": {},
"status": "active"
}
Delete Channel
Available in versions: v1, v2
DELETE /channel/{channel_id}
{
"id": 0,
"name": "string",
"type": "comagic",
"account_id": 0,
"context": {},
"status": "active"
}
Create Chat
Available in versions: v1, v2
POST /chat
{
"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"
}
Update Chat
Available in versions: v2
PATCH /chat
{
"context": {},
"account_id": 0,
"channel_id": 0,
"chat_id": 0,
"operator_id": 0
}
Close Chat
Available in versions: v1, v2
POST /chat/close
{
"context": {},
"account_id": 0,
"channel_id": 0,
"chat_id": 0,
"operator_id": 0,
"reason": "closedbytimeout"
}
operator
id is optional.
Assign Chat to Operator
Available in versions: v1
POST /chat/operator
{
"context": {},
"account_id": 0,
"channel_id": 0,
"chat_id": 0,
"operator_id": 0
}
Send Message
Available in versions: v1, v2
POST /message
{
"context": {},
"account_id": 0,
"channel_id": 0,
"id": 0,
"chat_id": 0,
"source": "system",
"operator_id": 0,
"replytoid": 0,
"text": "string",
"created_at": "2023-01-01T00:00:00.001Z",
"status": "accepted",
"resource": {
"id": 0,
"token": "string",
"type": "photo",
"name": "string",
"size": 0
},
"systemmessagemnemonic": "string"
}
The status parameter can have the following values: accepted
, delivered
, read
, sent
, error
.
Update Message
Update Message Status
Available in versions: v1, v2
POST /message/status
{
"context": {},
"account_id": 0,
"channel_id": 0,
"chat_id": 0,
"message_id": 0,
"status": "accepted"
}
Update Visitor Information
Available in versions: v1, v2
POST /visitor/card
{
"context": {},
"account_id": 0,
"channel_id": 0,
"visitor_id": 0,
"visitor_card": {}
}
Visitor Card Object Description
Parameter | Type | Description |
name |
str | Visitor’s name |
company |
str | Visitor’s company |
comment |
str | Additional comment |
phones |
list[str] | List of phone numbers |
emails |
list[str] | List of email addresses |
Transition from Webhook v1 to v2
Key Differences:
- Instead of a webook for chat assignment to an operator, v2 uses a chat update request.
- A new message update webhook has been added.
Working with WABA Channels
WABA (WhatsApp Business API) channels have specific restrictions:
- Outbound communications can only be initiated using predefined templates.
- Conversations can only take place within a time window, which starts when a visitor responds to an operator’s message.
Information about available templates (and their modifications) is sent in webhooks related to the channel in the attribute context["message_templates"]
, which is a list[MessageTemplate]
.
To fully support WABA templates, the adapter must implement webhook version v2.
MessageTemplate
Structure:
Parameter | Type | Description |
id |
int | Template identifier |
name |
str | Template name |
content |
MessageTemplateContent | Template content |
createdAt |
datetime | Date and time of template creation |
MessageTemplateContent
Structure:
Parameter | Type | Description |
text |
str | Message text |
header |
MessageTemplateContentHeader | Header |
footer |
MessageTemplateContentFooter | Footer |
keyboard |
MessageTemplateContentKeyboard | Menu buttons |
MessageTemplateContentHeader
Structure:
Parameter | Type | Description |
text |
Optional[str] | Header text |
headerType |
Optional[enum] | Header type. Allowed values: TEXT , VIDEO , IMAGE , DOCUMENT |
headerExampleMediaUrl |
Optional[str] | Example media URL |
MessageTemplateContentFooter
Structure:
Parameter | Type | Description |
text |
Optional[str] | Footer text |
MessageTemplateContentKeyboard
Object Structure:
Parameter | Type | Description |
rows |
list[MessageTemplateContentKeyboardRow] | List of keyboard rows |
MessageTemplateContentKeyboardRow
Object Structure:
Parameter | Type | Description |
buttons |
list[MessageTemplateContentButton] | List of buttons |
MessageTemplateContentButton
Object Structure:
Parameter | Type | Description |
text |
str | Button text |
buttonType |
enum | Button type. Allowed values: QUICK_REPLY , URL , PHONE |
payload |
str | Reply text (for QUICK_REPLY buttons only) |
url |
str | Link (for URL buttons only) |
phone |
str | Phone number (for PHONE buttons only) |
Send Message Using Template
To send a message with a template, use the message-sending method. The template is passed in the attribute context[template]
in the following format:
Parameter | Type | Description |
id |
int | Template identifier |
text |
str | Message text |
header |
MessageTemplateContentHeader | Header |
footer |
MessageTemplateContentFooter | Footer |
keyboard |
MessageTemplateContentKeyboard | Menu buttons |
Conversation Time Window
The time window information is sent in the new message
and message update
webhooks in the attribute context["conversationframets"]
(type: int
).
- The value is a UNIX timestamp indicating when the time window expires.
- If this attribute is missing or empty, the time window is considered closed.
Changelog
1.7.0 (2024-12-09)
- Added information about the new callback version v2.
- Expanded the list of channel types that the adapter can use.
- Added details on working with WABA channels.
1.6.0 (2024-10-01)
- Added information about the new adapter attribute webhook_auth.
1.5.1 (2024-09-26)
- Added callback information in the Agreements section.
1.5.0 (2024-04-11)
- Added versioning information for callbacks.
- Implemented the chat closure method.
- Added a new method for chat transfer.
1.4.0 (2023-09-18)
- Added authentication token retrieval details (login to the personal account).
1.3.0 (2023-09-18)
- Removed the redundant visitor_id attribute from the new message event.
1.2.0 (2023-09-14)
- Removed redundant attributes appid and siteid from all events.
1.1.0 (2023-09-13)
- Updated authentication information.
1.0.0 (2023-09-12)
- Initial release.