question

jscgroup1032 avatar image
jscgroup1032 asked John Wang Deactivated answered

Can you use JavaScript SDK to read incoming SMS messages

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.

sdk
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

John Wang avatar image
John Wang Deactivated answered
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.
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys