Sending an RCS message

Learn how to quickly send RCS messages in a Node.js application with the Sinch RCS API.

What you need to know before you start

RCS is currently only supported on Android handsets and needs to be enabled in the messaging client being used on the device (for example, Google Messages, Samsung Messages, or another messaging client). As such, you will need a compatible Android device with chat features turned on in the messaging client.

You will also need access to one of the Sinch Demo Sender Identities which will be provided to you upon acceptance to the Closed Beta program.

Set up your Node.js application

Create a new node app with npm.

npm init

Accept the defaults for the application. Add the fetch package with npm to generate the necessary dependencies.

npm install 'node-fetch'

Note:

The node fetch package requires us to use node modules, so we need to use a .mjs file type instead of a .js.

Create your file

Create a new file named index.mjs in the project and paste the provided "Send an RCS message" code into the file.

Send an RCS message

// Get a Sinch Demo Sender ID and API Token from your Account Manager
const senderID = '';
const apiToken = '';
const toNumber = '';

import fetch from 'node-fetch';

async function run() {
  const resp = await fetch(
    'https://us.rcs.api.sinch.com/rcs/v1/' + senderID + '/messages',
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        Authorization: 'Bearer ' + apiToken
      },
      body: JSON.stringify({
        to: toNumber,
        message: {
          type: 'text',
          text: 'Test message!'
        }
      })
    }
  );

  const data = await resp.json();
  console.log(data);
}

run();

Fill in your parameters

Assign your values to the following parameters:

ParameterYour value
senderIDThe demo Sender ID sent to you by your account manager
apiTokenThe API token sent to you by your account manager
toNumberThe phone number to which you want to send the test RCS message

Save the file.

Send your first RCS message

Now you can execute the code and send your test SMS message. Run the following command:

node index.js

Next steps

The code you used in the index.mjs file sends a POST request to the Sinch API /batches endpoint to send the SMS message. Click here to read more about the batches endpoint.

Was this page helpful?

Send an RCS message

// Get a Sinch Demo Sender ID and API Token from your Account Manager
const senderID = '';
const apiToken = '';
const toNumber = '';

import fetch from 'node-fetch';

async function run() {
  const resp = await fetch(
    'https://us.rcs.api.sinch.com/rcs/v1/' + senderID + '/messages',
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        Authorization: 'Bearer ' + apiToken
      },
      body: JSON.stringify({
        to: toNumber,
        message: {
          type: 'text',
          text: 'Test message!'
        }
      })
    }
  );

  const data = await resp.json();
  console.log(data);
}

run();