@cmdotcom/text-sdk:一个发送短信的助手库.
想要在您的 Node.js 应用程序中发送文本消息吗 ? 那你来对地方了.
该软件包目前与CM网关相比在特性上受到限制,但如果想要获得所有功能,请前往: CM.com API 文档
使用量
节点JS
第一,跑开 npm install @cmdotcom/text-sdk。然后,在您的源文件中:
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);
});
或发送多
const result = myMessageApi.sendTextMessage(["00316012345678","003160000000"], "TestSender", "Hello world?!");
使用信件构建器发送丰富的信件
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);
});
或使用信件创建器发送什么程序模板消息
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);
});
或使用信件构建器发送什么 app 交互式信件
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);
});
许可证
@cmdotcom/text-sdk属于麻省理工学院许可. 见LICENSE文件.