Contact support:
Contact support
Select Language Русский English

    Receiving incoming events

    There are two ways to receive incoming API events:

    To work with the pusher-api, many ready-made libraries are available in different programming languages. Let’s consider an example of receiving events using the pusher-js library.

    1. Include pusher-js

    <script src="https://js.pusher.com/7.0/pusher.min.js"></script>
    2. Configure the connection

    Note: In the connection settings, you only need to specify your accessToken obtained via the v1.tokens.make method (do not change other variables).

    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 via v1.tokens.make
            }
        },
        enabledTransports: ['ws'],
        forceTLS: true
    });
    3. Subscribe to a private channel

    There are 3 types of private channels:

    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 corresponds to one channel.
    1229 is your line ID.
    grWhatsApp is the messenger type in the line.

    let channelCompany = pusher.subscribe('private-v1.companies.2224');

    Note: One company equals one channel.
    2224 is your company ID.

    let channelUser = pusher.subscribe('private-v1.users.685');
    Note: One user equals one channel. 685 is the user ID.
    4. Listen to incoming events
    // incoming/outgoing message
    channel.bind('message', (data) => {
        console.log(data);
    });
    
    // message sending status
    channel.bind('messageStatus', (data) => {
        console.log(data);
    });
    
    // chat tag added/removed
    channel.bind('chatTag', (data) => {
        console.log(data);
    });
    
    // employee status
    channelCompany.bind('employeeStatus', (data) => {
        console.log(data);
    });
    
    // quick response added/updated/deleted
    channelUser.bind('quickResponse', (data) => {
        console.log(data);
    });
    Available events for messenger line channel:

    Available events for company channel:

    Available events for user channel:

    Full 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'
                }
            },
            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>
    Example object: 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"
          }
        }
      ],
      "meta": {
        "type": "message",
        "licenseId": 1229,
        "messengerType": "telegram"
      }
    }
    Example object: messageSystem (system message)
    {
      "data": [
        {
          "id": "9f01676a",
          "type": "system",
          "message": {
            "text": "Set responsible Test Testov [685]"
          }
        }
      ]
    }
    Example object: messageStatus
    {
      "data": [
        {
          "id": "wamid...",
          "type": "failed",
          "time": 1706175215
        }
      ]
    }
    Example object: messageDestroy
    {
      "data": [
        {
          "id": "1252",
          "time": 1741266878
        }
      ]
    }
    Example object: messageReaction
    {
      "data": [
        {
          "id": "wamid...",
          "reaction": " ",
          "action": "react"
        }
      ]
    }

    Example object: chatTag

    {
      "data": [
        {
          "type": "add",
          "tag": {
            "id": 29,
            "name": "test 1"
          }
        }
      ]
    }

    Example object: chatConversation

    {
      "data": [
        {
          "conversation": {
            "id": "ccb637d1",
            "type": "BIC"
          }
        }
      ]
    }
    Example object: chatStatus
    {
      "data": [
        {
          "type": "close",
          "chat": {
            "id": "70000000000@c.us"
          }
        }
      ]
    }