npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

@cmdotcom/text-sdk

1.1.0 • Public • Published

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

Published on NPM Travis (.com) Codecov Codacy grade

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);
});

License

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

install

npm i @cmdotcom/text-sdk

Downloadsweekly downloads

18

version

1.1.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
Report a vulnerability