Can I retrieve the contents of an inbound text message via Push Notifications using the Subscription API ?

  • 1
  • Question
  • Updated 2 years ago

This question comes from one of our awesome RingCentral Developer's working on an application.

"We have an application where we set up event filters to listen to Message-Store events. Every time we get an Inbound message, we use the timestamp from the push notification to filter for the message contents from the Message-Store API. Can we read the contents of the message from the Push notification directly ?" 


Photo of AK

AK, Official Rep

  • 4,402 Points 4k badge 2x thumb

Posted 2 years ago

  • 1
Photo of AK

AK, Official Rep

  • 4,402 Points 4k badge 2x thumb

Yes. This is now possible using the following event filters :

‘/restapi/v1.0/account/~/extension/' + extension_number + '/message-store/instant?type=SMS’


Consider the following subscription creation request:

POST .../restapi/v1.0/subscription
{
    "eventFilters": [
        "/restapi/v1.0/account/~/extension/' + extension_number + '/message-store/instant?type=SMS”
    ],
    "deliveryMode": {
      "transportType": "PubNub"
    }
}    

In response to this request the client application will get all the required information to subscribe to a certain PubNub channel (see PubNub section below to get more information about PubNub subscribing) and receive push notifications for the selected event (message-store/instant in this case):

HTTP/1.1 200 OK
 {
  "uuid": "8dd3801a-334c-43bf-ac41-97371b1a22de",
  "event": "/restapi/v1.0/account/~/extension/131074004/message-store/instant?type=SMS",
  "timestamp": "2016-08-16T02:52:29.561Z",
  "subscriptionId": "c342f21b-edae-4f33-85ce-3ef56ed8b5ad",
  "body": {
    "id": "1941536005",
    "to": [
      {
        "phoneNumber": "101",
        "name": “Sample_User"
      }
    ],
    "from": {
      "phoneNumber": “XXXXXXXXXXX"
    },
    "type": "SMS",
    "creationTime": "2016-08-16T02:52:29.522Z",
    "lastModifiedTime": "2016-08-16T02:52:29.522Z",
    "readStatus": "Unread",
    "priority": "Normal",
    "attachments": [
      {
        "id": "1941536005",
        "type": "Text",
        "contentType": "text/plain"
      }
    ],
    "direction": "Inbound",
    "availability": "Alive",
    "subject": "This is an Inbound Message",
    "messageStatus": "Received"
  }
}


From above, the parameter ‘subject’ could be used to read the contents off of the push notification for any inbound messages. 

P.S : This event filter could be used to retrieve the contents of Inbound Messages Only. 

Advantages:

1.) You would not have to listen to the “timestamp” from the Push notification anymore.

2.) You would not have to make an API call to “message-store” endpoint to filter using the ‘timestamp’ to retrieve the contents.


For more information on Subscription, please refer to our API Documentation here : 

Subscription API: https://developer.ringcentral.com/api-docs/latest/index.html#!#Notifications.html

SDKs: https://developers.ringcentral.com/library/sdks.html