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:
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.