Can you use JavaScript SDK to read incoming SMS messages

  • 2
  • Question
  • Updated 2 years ago
  • (Edited)
Is there any way to read incoming SMS using JavaScript SDK/API. If so can you please provide more details including where to download the SDK/APIs.
Photo of jscgroup

jscgroup

  • 80 Points 75 badge 2x thumb

Posted 2 years ago

  • 2
Photo of John Wang

John Wang, Official Rep

  • 5,278 Points 5k badge 2x thumb
You can do this using the API and JavaScript SDK. There's more than one day to do this so it would help to know how you intend to use the messages that are retrieved Do you intend to sync a datastore of SMS messages or to use them in another downstream action?

One way to do this requires two steps as shown below. There are other ways to do this so please let us know your use case.

1. Subscribing for events on the message store to receive information on new SMS messages
2. Retrieving the messages from the message store by querying the store for the time range

Step 1: Subscription for new SMS events:

For step one, you can subscribe to the ''/restapi/v1.0/account/~/extension/~/message-store'' event filter where ~ indicates your currently authorized account_id and extension_id. When receiving an event, you will receive an array of "changes" of which, some can have the "type" attribute set to "SMS" along with a "newCount" attribute. When "newCount" is > 0, there is a new SMS. Information on subscription is here:

Dev Guide: https://developer.ringcentral.com/api-docs/latest/index.html#!#Notifications.html
API Reference: https://developer.ringcentral.com/api-docs/latest/index.html#!#RefNotifications.html

Step 2: SMS Retrieval

To retrieve the new SMS message, call the message-store endpoint. Use the event's "body.lastUpdated" time attribute to query the message-store. You can limit the message-store query by setting the "dateFrom" and "dateTo" to around the "body.lastUpdated" time, e.g. set "dateFrom" and "dateTo" to 1 second less and greater than the "body.lastUpdated" time respectively. Upon receiving an array of messages, filter on the message's "lastModifiedTime" which will match the event's "body.lastUpdated" time.

Dev Guide: https://developer.ringcentral.com/api-docs/latest/index.html#!#MessagingGuide.html
API Reference: https://developer.ringcentral.com/api-docs/latest/index.html#!#MessageList.html

Example Implementation

This is implemented in the community Ruby SDK which posts each incoming message to the Glip chat service.

Script: https://github.com/grokify/ringcentral-sdk-ruby/blob/master/scripts/sms_to_chat.rb

This post is now included with the Ruby SDK here:

http://ringcentral-sdk-ruby.readthedocs.org/en/latest/usage/notifications/Subscribe_for_New_SMS/

You can take the same concepts and implement this in JavaScript.
(Edited)