Receiving inbound API events
Incoming api events can be received in real time via websockets using the protocol pusher-api.
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
let pusher = new Pusher('ChatsAppApiProdKey', {
wsHost: 'api.chatapp.online',
wssPort: 6001,
disableStats: true,
authEndpoint: 'https://api.chatapp.online/broadcasting/auth',
auth: {
headers: {
'Authorization': '$2y$10$l.SQOBOaqz3ZU65JAlEK4ughTCzIbcVGpJIUNTVnGpaKOYOd4M' // personal token obtained by the method https://api.chatapp.online/docs/#1-v1tokens-POSTv1-tokens
}
},
enabledTransports: ['ws'],
forceTLS: true
});
3. We connect to a private channel
let channel = pusher.subscribe('private-v1.licenses.1229.messengers.grayWhatsApp');
// or
let channel = pusher.subscribe('private-v1.licenses.1229.messengers.telegram');
Note: One messenger in one license is one channel.
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);
});
Available events:
- message (incoming/outgoing message)
- messageStatus (sent message status)
- chatTag (added/removed tag for chat)
- chatConversation (open 24 hour window (only available for whatsapp))
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: 'api.chatapp.online',
wssPort: 6001,
disableStats: true,
authEndpoint: 'https://api.chatapp.online/broadcasting/auth',
auth: {
headers: {
'Authorization': '$2y$10$l.SQOBOaqz3ZU65JAlEK4ughTCzIbcVGpJIUNTVnGpaKOYOd4M' //personal token obtained by the method https://api.chatapp.online/docs/#1-v1tokens-POSTv1-tokens
}
},
enabledTransports: ['ws'],
forceTLS: true
});
let channel = pusher.subscribe('private-v1.licenses.1229.messengers.grayWhatsApp');
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);
});
};
</script>
Object example message (incoming/outgoing message)
{
"queue": "Telegram.Broadcast.Message",
"payload": {
"data": [
{
"id": 696,
"fromApi": false,
"fromMe": false,
"side": "in",
"time": 1637319282,
"isForwarded": false,
"type": "text",
"message": {
"text": "Test",
"caption": "",
"file": null
},
"quotedMessage": null,
"fromUser": {
"id": 1480675234,
"username": "username_test",
"name": "Test Test",
"phone": "7000000000"
},
"chat": {
"id": "private-1480005234h1360003129730259258",
"hash": "h1360003129730259258",
"type": "private",
"phone": "7000000000",
"username": "username_test",
"name": "Test Test",
"image": "https://telegramclientapi.app24.online/GetDialogPhoto/3bf70000-941b-4e19-bc31-56e150a0e900"
},
"fromApp": null
}
],
"meta": {
"type": "message",
"licenseId": 1229,
"messengerType": "telegram"
}
}
}
Object example messageStatus (Sent message status)
{
"queue": "Telegram.Broadcast.Message.Status",
"payload": {
"data": [
{
"id": 42213,
"type": "delivered", // delivered|viewed|failed
"chat": {
"id": "private-1480000234h1367520000730259258",
"hash": "h1367520000730259258",
"type": "private",
"phone": "70000000000",
"username": "username_test"
},
"fromApp": {
"id": "app_123_1",
"tracking": null
},
"error": null
}
],
"meta": {
"type": "messageStatus",
"licenseId": 1229,
"messengerType": "telegram"
}
}
}
Object example chatTag (added/removed tag for chat)
{
"queue": "Telegram.Broadcast.ChatTag",
"payload": {
"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))
{
"queue": "WhatsApp.Broadcast.ChatConversation",
"payload": {
"data": [
{
"conversation": {
"id": "ccb637d17ba3aced8051abc263bd72e4",
"type": "BIC",
"startTime": 1644500500,
"endTime": 1644586900
},
"chat": {
"id": "70000000000"
}
}
],
"meta": {
"type": "chatConversation",
"licenseId": 1229,
"messengerType": "WhatsApp"
}
}
}
- Installing Application
- Channels connection
- Messenger integration
- WhatsApp integration
- WhatsApp Business API integration
- Telegram integration
- Viber integration in Bitrix 24
- Telegram bot integration
- Integration of Avito
- How to start a dialogue with a Telegram user
- Send message first from CRM
- Duplicate leads and deals
- About BotApp24
- Install BotApp24
- Teach Chatbot
- Create Chatbot
- Connect Chatbot to Bitrix24
- Add Chatbot to Open Channel
- Test Chatbot
- Configure Data Collection
- Chatbot Response to WhatsApp Calls
- Setting up a chatbot to collect feedback
- Configure Regular Expressions
- Special Characters for Regular Expressions
- FAQ. BotApp24
- Connection ChatApp API
- Receiving inbound API events
- Getting an access to ChatApp API