Messages Provider

The Messages provider allows you to listen for webhooks from the Messages API.

Functions

  • onMessage - this function allows you to listen for incoming messages using the Messages API. See the code snippet here.
  • onMessageEvent - this function allows you to listen for incoming events using the Messages API. See the code snippet here.

Note: Use the vcr.verifyAuth method to verify that callbacks originate from the Cloud Runtime Platform.

Receive Inbound SMS Webhooks

Inbound SMS to your Vonage numbers can either be handled by the SMS API or the Messages API. Vonage Cloud Runtime uses the Messages API, so to receive inbound SMS messages to your applications you will need to update your API Settings on the Vonage Dashboard to send inbound SMS webhooks to the Messages API:

API Settings SMS Webhook Toggle

Initializing the Messages Provider

To use the Messages Provider you need to create an instance of the provider using a session:

const session = vcr.createSession();
const messaging = new Messages(session);

Use Case

For example, to use the Messages provider to listen for all inbound SMS messages to Vonage number:

const session = vcr.createSession();
const messaging = new Messages(session);

const vonageNumber = { type: "sms", number: "447700900000" };
const from = { type: "sms", number: null }; 

await messaging.onMessage("onMessage", from, vonageNumber);