Prerequisite: Get dedicated phone numbers from the Momentic team before proceeding.

Momentic allows you to send and receive SMS messages in your tests. This feature is useful for testing SMS-based authentication, notifications, and other features that require sending and receiving SMS messages.

Usage

SMS support is currently surfaced through the JavaScript step. Within Momentic’s JavaScript sandbox, your code can access a special sms object. This object contains the following utility functions:

Send SMS

The send utility function allows you to send an SMS message to a phone number. The phone number provided in the from argument must be issued and authorized by Momentic.

async function send(params: {
  body: string;
  to: string;
  from: string;
}): Promise<void>;

Fetch SMS message

The fetchLatest utility function retrieves the most recent SMS message sent to your phone number. You can filter messages based on the sender as well as the receipt date. This function will automatically retry until a matching message is found or the timeout is exhausted (if no timeout is provided, the default is 10 seconds).

If multiple new SMS messages are received, only the most recently received message will be returned. To avoid race conditions, we recommend structuring your tests so that only a single SMS flow is active at any given time for each phone number allocated to your organization.

If you do not filter by receipt date, fetchLatest can return messages that were received before your test started (i.e. data generated from previous test runs).

fetchLatest will throw an error if no matching SMS message is received within the timeout.

async function fetchLatest(params: {
  to: string;
  from?: string;
  beforeDate?: Date;
  afterDate?: Date;
  timeout?: number; // milliseconds
}): Promise<{ body: string }>;