Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@cmdotcom/text-sdk

cmdotcom7.1kMIT2.1.0TypeScript support: included

Package to make it very easy to send text messages with CM.com

cm, cm.com, sms, messaging, text, rcs, api, messaging, text, sms, push, whatsapp, viber, wechat, rcs, voice, business messaging, telegram, conversational, sms chat, chat, sms 2.0, rbm, mms, rich sms, rich communication services, twitter

readme

@cmdotcom/text-sdk: A helper library to send text messages.

Published on NPM Node.js CI Codecov

Want to send text-messages in your Node.js application? Then you are at the right place.

The package is currently limited in features compared to the CM gateway, but if you want to get all the functionalities, go to: CM.com API Docs

Usage

Node.JS

First, run npm install @cmdotcom/text-sdk. Then, in your source file:

const messagingApi = require("@cmdotcom/text-sdk");

// Get your product token at CM.com.
const yourProductToken = "";
const myMessageApi = new messagingApi.MessageApiClient(yourProductToken);

const result = myMessageApi.sendTextMessage(["00316012345678"], "TestSender", "Hello world?!");

result.then((result) => {
    console.log(result);
}).catch((error) => {
    console.log(error);
});

or send multiple

const result = myMessageApi.sendTextMessage(["00316012345678","003160000000"], "TestSender", "Hello world?!");

send rich messages using the message builder

const richMessage = {
    media: {
        mediaName: "cm.com",
        mediaUri: "https://avatars3.githubusercontent.com/u/8234794?s=200&v=4"
    },
    text: "Our logo!"
};

const suggestion = {
    action: "openUrl",
    label: "Click me",
    url: "https://www.cm.com"
};

const response = client.createMessage()
    .setMessage(["00316012345678"], "TestSender", "Hello world?!")
    .setAllowedChannels(["Viber"])
    .setConversation([richMessage])
    .setSuggestion([suggestion])
    .send();

response.then((result) => {
    console.log(result);
}).catch((error) => {
    console.log(error);
});

or send whatsapp template messages using the message builder

const template = {
    whatsapp: {
        elementName: 'template-name',
        language: {
            code: 'en',
            policy: 'deterministic'
        },
        namespace: 'the-namespace-of-template',
        components: [{
            type: 'body',
            parameters: [{
                type: 'text',
                text: 'firstname'
            }]
        }]
    }
};

const response = client.createMessage()
    .setMessage(["00316012345678"], "TestSender", "Hello world?!")
    .setAllowedChannels(["WhatsApp"])
    .setTemplate(template)
    .send();

response.then((result) => {
    console.log(result);
}).catch((error) => {
    console.log(error);
});

or send whatsapp interactive messages using the message builder

const whatsAppInteractiveContent = {
        type: 'list',
        header: {
            type: "text",
            text: "your-header-content"
        },
        body: {
            text: "your-text-message-content"
        },
        footer: {
            text: "your-footer-content"
        },
        action: {
            button: "cta-button-content",
            sections: [{
                title: "your-section-title1",
                rows: [{
                    id: "unique-row-identifier1",
                    title: "row-title-content",
                    description: "row-description-content"
                }]
            },
            {
                title: "your-section-title2",
                rows: [{
                    id: "unique-row-identifier2",
                    title: "row-title-content",
                    description: "row-description-content"
                }]
            }
            ]
        }
};

const response = client.createMessage()
    .setMessage(["00316012345678"], "TestSender", "Hello world?!")
    .setAllowedChannels(["WhatsApp"])
    .setInteractive(whatsAppInteractiveContent)
    .send();

response.then((result) => {
    console.log(result);
}).catch((error) => {
    console.log(error);
});

License

@cmdotcom/text-sdk is under the MIT license. See LICENSE file.

changelog

[2.1.0] - 2024-06-13

  • Update global endpoint
  • Fix misc urls in towards the dev docs

[2.0.0] - 2023-10-18

Added

  • Use axios to send HTTP requests

Changed

  • Removed dependencies on http, bluebird, request
  • Use customgrouping3 instead of customgrouping for categorization
  • Target ES2022 instead of ES5
  • Various package versions

Removed

  • Possibility to use a query string
  • Deprecated methods from MessageApiClient.ts

[1.4.1] - 2022-12-12

Changed

  • Update model for WhatsApp Interactive.

[1.4.0] - 2022-12-09

Added

  • Add missing models to send WhatsApp interactive messages
  • Add missing models to send Apple Messages for Business listpicker messages.

[1.3.6] - 2022-12-05

Added

  • Support for the Telegram channel

    Updated

  • Several dependency updates.

[1.3.5] - 2021-07-06

Added

  • Support for the Instagram channel

[1.3.4] - 2021-04-09

Added

  • Support for the Facebook Messenger and Google Business Messages channel

[1.3.3] - 2020-12-23

Added

  • Support for the MobilePush channel

[1.3.2] - 2020-08-20

Fixed

  • Moved from ClientResponse to IncomingMessage in the external api as well.

[1.3.1] - 2020-08-19

Fixed

  • Moved from ClientResponse to IncomingMessage to support higher node/ts versions.
  • Updated devDependencies to for audit fixes.

[1.3.0] - 2020-06-15

Added

  • Support for Twitter as channel.

Security

  • Updated dependencies (audit-fixes).

[1.2.0] - 2020-01-30

Added

  • Support for whatsapp templates.

Security

  • Updated dependencies (audit-fixes).

[1.1.0] - 2019-03-13

Added

  • Added several features for RichContent in messages.

[1.0.0] - 2019-02-21

Major

This version is set to 1.0.0, as 0.2.0 is stable for current users. Version itself does not include new features to the current limited set, but it will be easier to manage possible breaking changes from now on.

Dependencies

  • Updated dependencies (audit-fixes).

[0.2.0] - 2018-10-31

Added

  • Ability to set reference.
  • Added keywords in package.json.

[0.1.0] - 2018-09-27

Added

  • Shields and updated README.md

[0.0.1] - 2018-09-19

Added

  • Moved from Github(CMTelecom to cmdotcom).
  • Moved on npm to @cmdotcom.