Skip to main content
The First Step
Oct 14, 2021 5:49 PM UTC
Question

Outbound Messages - Instant Message Event

Is there a way to have outbound messages with the Instant Message Event? The payload example has a direction, but it seems this is only working for inbound.

If this is not the appropriate webhook, can someone point me to the correct event to have instant outbound messages?


    5 replies

    PhongVu
    Community Manager
    Community Manager
    Oct 15, 2021 2:23 PM UTC

    Unfortunately, outbound message notification does not include the message payload, nor the "from" and "to" info. What is your use case?

    The First Step
    Oct 19, 2021 3:57 PM UTC

    Hi Phong,

    We were trying to get all the SMS messages to ingest those in another system, we were taking a look, and we decide to use that event, as the payload had direction as a parameter, we were thinking Inbound and Outbound should be the values, but it seems only works for Inbound. After that, we decided to get Inbound with that event and Outbound with message-store?type=SMS&direction=Outbound and then get the Message ID and do an API call to getMessges to have the text of the messages + from and to.

    Do you know, for instant message events if there is another value for direction?


    Thanks


    The First Step
    Feb 16, 2023 1:07 PM UTC

    Hi Mr. @Phong Vu ,

    We are only receiving the webhook for inbound messages and there is no webhook call for outbound messages. Could you please suggest if there is a way to listen to outbound message events?


    Any help is highly appreciated.


    Thanks!

    The First Step
    Feb 16, 2023 1:43 PM UTC

    The only way we know how to do this is by running a job that checks to see if the message is sent ever minute. Is there not a better way? That solution is not ideal.

    We are building a CRM system where we send and receive texts to our clients from the system. We have no problems receiving the texts. Our problem is that we can't confirm if something is sent without running a job every minute.

    Please advise us on the best way to proceed. If we have to run the job ever minute, we can. We just want a better way if it is possible. Thank you in advance.

    PhongVu
    Community Manager
    Community Manager
    Feb 16, 2023 4:58 PM UTC

    Here is how you can get notified for both inbound and outbound new text message events

    var eventFilters = ['/restapi/v1.0/account/~/extension/~/message-store?type=SMS']
    
    // E.x using PubNub notification
    subscription.on(subscription.events.notification, async function(msg) {
        for (var message of msg.body.changes){
          for (var msgId of message.newMessageIds){
            await readMessageDetail(msgId)
          }
        }
    });
    
    async function readMessageDetail(msgId){
      try{
        var resp = await platform.get(`/restapi/v1.0/account/~/extension/~/message-store/${msgId}`)
        var jsonObj = await resp.json()
        console.log(JSON.stringify(jsonObj)
      }catch(e){
        console.log(e.message)
      }
    }

    Alternative way to get inbound text message with message detailed in the event body, and, you can subscribe for separate events as follows:

    '/restapi/v1.0/account/~/extension/244609004/message-store/instant?type=SMS'
    '/restapi/v1.0/account/~/extension/233723004/message-store?direction=Outbound&type=SMS',