There are two options for receiving incoming api events:
- Via webhooks - subscribe to webhooks
- Via websockets using pusher-api protocol
Many ready-made libraries in different programming languages.
Below is an example of connecting through a library pusher-js.
1. We connect the library pusher-js
<script src="https://js.pusher.com/7.0/pusher.min.js"></script>
2. Set up the connection settings
Note: In the connection settings, you only need to specify your accessToken obtained by the method v1.tokens.make (no other variables need to be changed).
let pusher = new Pusher('ChatsAppApiProdKey', {
wsHost: 'socket.chatapp.online',
wssPort: 6001,
disableStats: true,
authEndpoint: 'https://api.chatapp.online/broadcasting/auth',
auth: {
headers: {
'Authorization': '$2y$10$l.SQOBOaqz3ZU65JAlEK4ughTCzIbcVGpJIUNTVnGpaKOYOd4M' // accessToken obtained by the method v1.tokens.make
}
},
enabledTransports: ['ws'],
forceTLS: true
});
3. We connect to a private channel
There are 3 types of private channels in total:
- private-v1.licenses.1229.messengers.grWhatsApp - messenger channel in line
- private-v1.companies.2224 - company channel
- private-v1.users.685 - user channel
let channel = pusher.subscribe('private-v1.licenses.1229.messengers.grWhatsApp');
// or
let channel = pusher.subscribe('private-v1.licenses.1229.messengers.telegram');
Note: One messenger in one line is one channel. 1229 is your line number. grWhatsApp is the messenger type in the line.
let channelCompany = pusher.subscribe('private-v1.companies.2224');
Note: One company - one channel. 2224 - is your company number.
let channelUser = pusher.subscribe('private-v1.users.685');
Note: One user - one channel. 685 - is the user id.
4. Listening to incoming events
// incoming/outgoing message
channel.bind('message', (data) => {
console.log(data);
});
// sent message status
channel.bind('messageStatus', (data) => {
console.log(data);
});
// added/removed tag for chat
channel.bind('chatTag', (data) => {
console.log(data);
});
// employee status
channelCompany.bind('employeeStatus', (data) => {
console.log(data);
});
// create/edit/destroy quick response
channelUser.bind('quickResponse', (data) => {
console.log(data);
});
Available events for the channel - line-messenger:
- message (incoming/outgoing message)
- messageSystem (system message)
- messageStatus (sent message status)
- messageDestroy (delete a message)
- messageReaction (reaction for message)
- chatTag (added/removed tag for chat)
- chatStatus (set status for chat)
- chatResponsible (set responsible for chat)
- chatResponsiblePin (pin/unpin responsible for chat)
- chatProducer (set producer for chat)
- chatAccomplice (added/removed accomplice for chat)
- chatAuditor (added/removed auditor for chat)
- chatLevel (set level for chat)
- chatConversation (open 24 hour window (only available for whatsapp))
- chatRead (chat marked as read)
- chatUnread (chat marked as unread)
- chatProcess (set process for chat)
- chatParticipantAdd (add participant to group (available for telegram and telegramBot))
- chatParticipantDestroy (remove participant from group (available for telegram and telegramBot))
- chatComment (set comment for chat)
- chatConsentSendMessage (set consent to send messages for chat)
- chatArchive (chat added to archive or chat restored from archive)
- chatCustomField (changed the value of the custom chat field)
Available events for the channel - company:
- employeeStatus (employee status)
- employeeWorkday (employee workday)
Available events for the channel - user:
- quickResponseList (create/edit/destroy quick response list)
- quickResponse (create/edit/destroy quick response)
Complete example code:
<script src="https://js.pusher.com/7.0/pusher.min.js"></script>
<script>
window.onload = function() {
let pusher = new Pusher('ChatsAppApiProdKey', {
wsHost: 'socket.chatapp.online',
wssPort: 6001,
disableStats: true,
authEndpoint: 'https://api.chatapp.online/broadcasting/auth',
auth: {
headers: {
'Authorization': '$2y$10$l.SQOBOaqz3ZU65JAlEK4ughTCzIbcVGpJIUNTVnGpaKOYOd4M' // accessToken obtained by the method v1.tokens.make
}
},
enabledTransports: ['ws'],
forceTLS: true
});
let channel = pusher.subscribe('private-v1.licenses.1229.messengers.grWhatsApp');
channel.bind('message', (data) => {
console.log(data);
});
channel.bind('messageStatus', (data) => {
console.log(data);
});
channel.bind('chatTag', (data) => {
console.log(data);
});
let channel2 = pusher.subscribe('private-v1.licenses.1229.messengers.telegram');
channel2.bind('message', (data) => {
console.log(data);
});
channel2.bind('messageStatus', (data) => {
console.log(data);
});
channel2.bind('chatTag', (data) => {
console.log(data);
});
let channelCompany = pusher.subscribe('private-v1.companies.2224');
channelCompany.bind('employeeStatus', (data) => {
console.log(data);
});
let channelUser = pusher.subscribe('private-v1.users.685');
channelUser.bind('quickResponseList', (data) => {
console.log(data);
});
channelUser.bind('quickResponse', (data) => {
console.log(data);
});
};
</script>
Object example message (incoming/outgoing message):
{
"data": [
{
"id": "123",
"internalId": 37914,
"groupId": null,
"fromApi": false,
"fromMe": false,
"side": "in",
"time": 1637319282,
"type": "text",
"subtype": null,
"message": {
"text": "Test",
"textLang": null,
"caption": "",
"file": null,
"location": null,
"template": null,
"html": ""
},
"quotedMessage": {
"id": "122",
"type": "text",
"subtype": null,
"message": {
"text": "test",
"textLang": null,
"caption": "",
"file": null,
"location": null,
"template": null,
"html": ""
}
},
"fromUser": {
"id": "1480675234",
"username": "username_test",
"name": "Test Test",
"phone": "7000000000",
"email": null
},
"chat": {
"id": "private-1480005234h1360003129730259258",
"internalId": 199167,
"hash": null,
"type": "private",
"phone": "7000000000",
"username": "username_test",
"email": null,
"name": "Test Test",
"image": "https://test.test/GetDialogPhoto/3bf70000-941b-4e19-50a0e900",
"lastTime": 1718789705,
"link": null,
"tags": [
{
"id": 6,
"name": "test",
"color": "hhhh",
"sort": 100,
"category": {
"id": 13,
"name": "test",
"sort": 100
}
}
],
"responsible": {
"id": 685
},
"producer": {
"id": 685
},
"accomplices": [
{
"id": 100
}
],
"auditors": [
{
"id": 100
}
],
"status": "close",
"level": null,
"responsiblePin": false,
"process": null,
"timeLastInMessage": 1718789705,
"unreadMessages": 1,
"lastRead": 1718785472,
"advert": null,
"secondLink": null,
"subtype": null,
"inviteLink": null,
"lastMessage": {
"type": "text",
"previewText": "Тест",
"previewTextLang": null
},
"comment": null,
"consentSendMessage": null,
"archive": false,
"customFields": [
{
"id": 32,
"name": "Float field",
"type": "numeric",
"sort": 105,
"options": null,
"value": 1234.66672
},
{
"id": 21,
"name": "Select field",
"type": "select",
"sort": 105,
"options": [
{
"id": 205,
"value": "Значение 4",
"sort": 400
},
{
"id": 206,
"value": "Значение 4",
"sort": 400
}
],
"value": 205
}
]
},
"fromApp": null,
"utm": null,
"created": null,
"forwarded": true,
"edited": false
}
],
"meta": {
"type": "message",
"licenseId": 1229,
"messengerType": "telegram"
}
}
Object example messageSystem (system message):
{
"data": [
{
"id": "9f01676a-cbe9-4fbc-bd46-5286b4195fdc",
"internalId": 40551,
"groupId": null,
"fromApi": true,
"fromMe": true,
"side": "out",
"time": 1724309901,
"type": "system",
"subtype": null,
"message": {
"text": "Set responsible Test Testov [685]",
"textLang": {
"en": "Set responsible Test Testov [685]",
"ru": "Назначен ответственный Test Testov [685]",
"pt": "Set responsável Test Testov [685]"
},
"caption": "",
"file": null,
"location": null,
"template": null,
"html": ""
},
"quotedMessage": null,
"fromUser": {
"id": null,
"username": null,
"name": "test",
"phone": null,
"email": null
},
"chat": {
"id": "70000000000@c.us",
"internalId": 199167,
"fullId": "aeec7c86edd95240f07af53427cbcd48",
"hash": null,
"type": "private",
"phone": "70000000000",
"username": null,
"email": null,
"name": "Test Test",
"image": "https://pps.whatsapp.net/v/t62.24694-24/42954918280157_n.jpg",
"lastTime": 1724309901,
"link": null,
"tags": [
{
"id": 9,
"name": "test",
"color": "#123df",
"sort": 1111,
"category": []
},
{
"id": 11,
"name": "test 2",
"color": "#123df",
"sort": 1111,
"category": []
}
],
"responsible": {
"id": 685
},
"producer": {
"id": 685
},
"accomplices": null,
"auditors": null,
"status": "open",
"level": {
"id": 555
},
"responsiblePin": false,
"process": null,
"timeLastInMessage": 1724309838,
"unreadMessages": 1,
"lastRead": 1724237989,
"advert": null,
"secondLink": null,
"subtype": null,
"inviteLink": null,
"lastMessage": {
"type": "system",
"previewText": "Set responsible Test Testov [685]",
"previewTextLang": {
"en": "Set responsible Test Testov [685]",
"ru": "Назначен ответственный Test Testov [685]",
"pt": "Set responsável Test Testov [685]"
},
},
"comment": null,
"consentSendMessage": null,
"archive": false,
"customFields": null
},
"fromApp": {
"id": "app_685_1",
"tracking": null,
"sender": null
},
"utm": null,
"created": {
"id": 685
},
"forwarded": false,
"edited": false
}
],
"meta": {
"type": "messageSystem",
"licenseId": 1229,
"messengerType": "grWhatsApp"
}
}
Object example messageStatus (sent message status):
{
"data": [
{
"id": "wamid.HBgQMzQzMjQ3OTYxNDkwMjAzNxUCABEYEkE5MDlBMTFERTBBQkVCQkMyRAA=",
"type": "failed", // delivered|viewed|failed|sent
"time": 1706175215,
"chat": {
"id": "70000000000",
"hash": null,
"type": "private",
"phone": "70000000000",
"username": null,
"email": null
},
"fromApp": {
"id": "app_123_1",
"tracking": null,
"sender": "employee"
},
"error": {
"code": 131026,
"message": "Message Undeliverable.",
"messageLang": {
"en": "Message Undeliverable.",
"ru": "Невозможно доставить сообщение.",
"pt": "Mensagem não entregue."
}
}
}
],
"meta": {
"type": "messageStatus",
"licenseId": 1229,
"messengerType": "caWhatsApp"
}
}
Object example messageDestroy (delete a message):
{
"data": [
{
"id": "1252",
"chat": {
"id": "private-243232294h-5444116472189911315"
}
}
],
"meta": {
"type": "messageDestroy",
"licenseId": 16402,
"messengerType": "telegram"
}
}
Object example messageReaction (reaction for message):
{
"data": [
{
"id": "wamid.HBgLNzk4OTk3MjU0NDIVAgARGBIyNjYzNkVEMTcyOTczMDgxMEEA",
"reaction": "😂",
"time": "1697795977",
"chat": {
"id": "79899725000"
},
"fromUser": {
"id": "79899725000",
"name": "Alisher Boy"
},
"action": "react" // unreact
}
],
"meta": {
"type": "messageReaction",
"licenseId": 1229,
"messengerType": "caWhatsApp"
}
}
Object example chatTag (added/removed tag for chat):
{
"data": [
{
"type": "add", // add|destroy
"tag": {
"id": 29,
"name": "test 1",
"color": "#123df55",
"sort": 100,
"category": {
"id": 9,
"name": "test 1",
"sort": 100
}
},
"chat": {
"id": "group-54911000655"
}
}
],
"meta": {
"type": "chatTag",
"licenseId": 1229,
"messengerType": "telegram"
}
}
Object example chatConversation (open 24 hour window (only available for whatsapp)):
{
"data": [
{
"conversation": {
"id": "ccb637d17ba3aced8051abc263bd72e4",
"type": "BIC",
"startTime": 1644500500,
"endTime": 1644586900
},
"chat": {
"id": "70000000000"
}
}
],
"meta": {
"type": "chatConversation",
"licenseId": 1229,
"messengerType": "WhatsApp"
}
}
Object example chatParticipantAdd (add participant to group (available for telegram and telegramBot))
{
"data": [
{
"chat": {
"id": -1002224731326
},
"participants": [
{
"id": 1234567,
"username": "test",
"name": "Test",
"phone": null
},
{
"id": 1234567,
"username": "test2",
"name": "Test 2",
"phone": null
}
]
}
],
"meta": {
"type": "chatParticipantAdd",
"licenseId": 1229,
"messengerType": "telegramBot"
}
}
Object example chatParticipantDestroy (remove participant from group (available for telegram and telegramBot))
{
"data": [
{
"chat": {
"id": -1002224731326
},
"participants": [
{
"id": 1234567,
"username": "test",
"name": "Test",
"phone": null
}
]
}
],
"meta": {
"type": "chatParticipantDestroy",
"licenseId": 1229,
"messengerType": "telegramBot"
}
}
Object example chatStatus (set status for chat):
{
"data": [
{
"type": "close",
"chat": {
"id": "70000000000@c.us"
}
}
],
"meta": {
"type": "chatStatus",
"licenseId": 1229,
"messengerType": "grWhatsApp"
}
}
Object example chatResponsible (set responsible for chat):
{
"data": [
{
"responsible": {
"id": 685
},
"chat": {
"id": "70000000000@c.us"
},
"fromApp": {
"id": "app_123_1"
},
"edited": {
"id": 685
}
}
],
"meta": {
"type": "chatResponsible",
"licenseId": 1229,
"messengerType": "grWhatsApp"
}
}
Object example chatResponsiblePin (pin/unpin responsible for chat):
{
"data": [
{
"type": "pin", // pin|unpin
"chat": {
"id": "70000000000@c.us"
}
}
],
"meta": {
"type": "chatResponsiblePin",
"licenseId": 1229,
"messengerType": "grWhatsApp"
}
}
Object example chatProducer (set producer for chat):
{
"data": [
{
"producer": {
"id": 685
},
"chat": {
"id": "70000000000@c.us"
},
"fromApp": {
"id": "app_123_1"
},
"edited": {
"id": 685
}
}
],
"meta": {
"type": "chatProducer",
"licenseId": 1229,
"messengerType": "grWhatsApp"
}
}
Object example chatAccomplice (added/removed accomplice for chat):
{
"data": [
{
"type": "add", // add|destroy
"accomplice": {
"id": 685
},
"chat": {
"id": "70000000000@c.us"
},
"fromApp": {
"id": "app_123_1"
},
"edited": {
"id": 685
}
}
],
"meta": {
"type": "chatAccomplice",
"licenseId": 1229,
"messengerType": "grWhatsApp"
}
}
Object example chatAuditor (added/removed auditor for chat):
{
"data": [
{
"type": "add", // add|destroy
"auditor": {
"id": 685
},
"chat": {
"id": "70000000000@c.us"
},
"fromApp": {
"id": "app_123_1"
},
"edited": {
"id": 685
}
}
],
"meta": {
"type": "chatAuditor",
"licenseId": 1229,
"messengerType": "grWhatsApp"
}
}
Object examplechatLevel (set level for chat):
{
"data": [
{
"level": {
"id": 555
},
"chat": {
"id": "70000000000@c.us"
},
"fromApp": {
"id": "app_685_1"
},
"edited": {
"id": 685
}
}
],
"meta": {
"type": "chatLevel",
"licenseId": 1229,
"messengerType": "grWhatsApp"
}
}
Object example chatRead (chat marked as read):
{
"data": [
{
"chat": {
"id": "7000000000@c.us"
}
}
],
"meta": {
"type": "chatRead",
"licenseId": "1229",
"messengerType": "grWhatsApp"
}
}
Object example chatUnread (chat marked as unread):
{
"data": [
{
"chat": {
"id": "7000000000@c.us"
}
}
],
"meta": {
"type": "chatUnread",
"licenseId": "1229",
"messengerType": "grWhatsApp"
}
}
Object example chatProcess (set process for chat):
{
"data": [
{
"process": "inWork", // null|inWork
"chat": {
"id": "70000000000@c.us"
},
"fromApp": {
"id": "app_685_1"
},
"edited": {
"id": 685
}
}
],
"meta": {
"type": "chatProcess",
"licenseId": 1229,
"messengerType": "grWhatsApp"
}
}
Object example employeeStatus (employee status):
{
"data": [
{
"type": "online",
"employee": {
"id": 685
}
}
],
"meta": {
"type": "employeeStatus",
"companyId": 2226
}
}
Object example employeeWorkday (employee workday):
{
"data": [
{
"type": "start|end",
"employee": {
"id": 685
}
}
],
"meta": {
"type": "employeeWorkday",
"companyId": 2226
}
}
Object example quickResponseList (create/edit quick response list):
{
"data": [
{
"type": "create", // create|edit
"quickResponseList": {
"id": 1338,
"name": "List name",
"sort": 100,
"access": [
{
"userId": "685",
"email": "test@test.test",
"permission": "w"
},
{
"userId": "124",
"email": "test2@test.test",
"permission": "r"
}
]
}
}
],
"meta": {
"type": "quickResponseList",
"userId": "685"
}
}
Object example quickResponseList (destroy quick response list):
{
"data": [
{
"type": "destroy",
"quickResponseList": {
"id": 1338
}
}
],
"meta": {
"type": "quickResponseList",
"userId": "685"
}
}
Object example quickResponse (create/edit quick response):
{
"data": [
{
"type": "create", // create|edit
"quickResponseList": {
"id": 1339
},
"quickResponse": {
"id": 1197,
"name": "Response name",
"sort": 300,
"parent": null,
"text": "Detail text",
"keywords": "test test2 test4",
"enableAI": true
}
}
],
"meta": {
"type": "quickResponse",
"userId": "685"
}
}
Object example quickResponse (destroy quick response):
{
"data": [
{
"type": "destroy",
"quickResponseList": {
"id": 1339
},
"quickResponse": {
"id": 1197
}
}
],
"meta": {
"type": "quickResponse",
"userId": "685"
}
}
Object example quickResponse (bulk destroy quick responses):
{
"data": [
{
"type": "destroy",
"quickResponseList": {
"id": 1339
},
"quickResponse": {
"id": 1197
}
},
{
"type": "destroy",
"quickResponseList": {
"id": 1339
},
"quickResponse": {
"id": 1198
}
}
],
"meta": {
"type": "quickResponse",
"userId": "685"
}
}
Object example chatComment (set comment for chat):
{
"data": [
{
"comment": "This is comment",
"chat": {
"id": "70000000000"
},
"fromApp": {
"id": "app_25095_1"
},
"edited": {
"id": 25095
}
}
],
"meta": {
"type": "chatComment",
"licenseId": 12345,
"messengerType": "WhatsApp"
}
}
Object example chatConsentSendMessage (set consent to send messages for chat):
{
"data": [
{
"consentSendMessage": "accepted",
"chat": {
"id": "70000000001@c.us"
},
"fromApp": {
"id": "app_25095_1"
},
"edited": {
"id": 25095
}
}
],
"meta": {
"type": "chatConsentSendMessage",
"licenseId": 1,
"messengerType": "grWhatsApp"
}
}
Object example chatArchive (chat added to archive or chat restored from archive):
{
"data": [
{
"archive": false, // true|false
"chat": {
"id": "70000000001@c.us"
}
}
],
"meta": {
"type": "chatArchive",
"licenseId": 1229,
"messengerType": "grWhatsApp"
}
}
Object example chatCustomField (changed the value of the custom chat field):
{
"data": [
{
"field": {
"id": 30,
"name": "String field",
"type": "string",
"sort": 105,
"options": null,
"value": "Test"
},
"chat": {
"id": "70000000001@c.us"
}
}
],
"meta": {
"type": "chatCustomField",
"licenseId": 1229,
"messengerType": "grWhatsApp"
}
}