@cmdotcom/text-sdk

中文文档
2.1.0发布于 2024/06/13MITTypeScriptCommonJS近 30 天下载 1.4万

用CM.com发送短信的软件包

中文使用文档
文档目录3 节
  1. @cmdotcom/text-sdk:一个发送短信的助手库.
  2. 使用量
  3. 许可证

@cmdotcom/text-sdk:一个发送短信的助手库.

Published on NPM Node.js CI Codecov

想要在您的 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文件.

版本与发布记录

@cmdotcom/text-sdk 共发布 17 个版本,首次发布于 2018/09/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.1.0latest2024/06/132 年前
2.0.02023/10/183 年前
1.4.12022/12/123 年前
1.4.02022/12/123 年前
1.3.62022/12/053 年前
1.3.52021/07/075 年前

关于 @cmdotcom/text-sdk 的常见问题

@cmdotcom/text-sdk 是什么?

用CM.com发送短信的软件包

如何安装 @cmdotcom/text-sdk?

在项目目录运行 npm install @cmdotcom/text-sdk,或使用 pnpm add / yarn add / bun add。

@cmdotcom/text-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cmdotcom/text-sdk 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@cmdotcom/text-sdk 可以商用吗?

@cmdotcom/text-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cmdotcom/text-sdk 的下载量有多少?

根据 npm 官方下载统计,@cmdotcom/text-sdk 在 2026/10/10 – 2026/11/08 这 30 天内被下载 13,545 次,日均约 452 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cmdotcom/text-sdk 还在维护吗?

最新版本 2.1.0 发布于 2024/06/13(2 年前);至今共发布 17 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/09/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。