@google/rcsbusinessmessaging

中文文档
1.0.10发布于 2024/08/14Apache-2.0CommonJS近 30 天下载 13.3万

RCS 商务信件 API 的节点帮助库

中文使用文档
文档目录17 节
  1. 文档
  2. 快速启动
  3. 在你开始之前
  4. 添加依赖关系
  5. 样本使用情况
  6. 初始化
  7. 发送附有建议的答复和行动的短信
  8. 发一张富豪卡
  9. 送木马
  10. 发送带有生命时间的信息
  11. 用过期时间发送信件
  12. 上传文件到 RMB 内容存储
  13. 发送先前上传的文件
  14. 版本
  15. 捐款
  16. 许可证
  17. 已知问题

Google的RCS业务消息:Node.js客户端

RCS 业务消息 以品牌,丰富的媒体,互动,分析等手段升级短信. 有了RCS,企业可以将品牌,互动的移动体验带入本地的Android短信应用.

本文件载有: API 参考,样品,以及开发Node.js应用的其他资源. 需要额外帮助开发RCS BusinessMessaging应用程序,使用Node.js和其他语言,参见我们 RCS 商业消息快速启动 向导.

文档

RCS 业务通讯 API 的文档可以找到 这里。 。 。 .

快速启动

在你开始之前

  1. 与 RCS 业务通讯注册。 。 。 .

添加依赖关系

在您的依赖性部分添加以下内容: package.json 数字 :

"dependencies": {
  ...
  "@google/rcsbusinessmessaging": "^1.0.10"
  ...
},

我们建议您使用最新版本 输入 npm 仓库。 。 。 .

样本使用情况

以下样本假设一个类似的库初始化,如 使用客户端库 节.

初始化

您通过提供您的服务账户密钥和代理代理ID来创建库 .

const SERVICE_ACCOUNT_PUBLIC_KEY = 'REPLACE_ME';

// Get the RCS Business Messaging client library helper
const rbmApiHelper = require('@google/rcsbusinessmessaging');

rbmApiHelper.initRbmApi(SERVICE_ACCOUNT_PUBLIC_KEY);
rbmApiHelper.setAgentId('myrbmagent'); // my agent id was [email protected]

自1.0.8发布以来,您可以选择将库禁用 特定区域终点。 这可以改善业绩,取决于 关于您代码的地理位置.

rbmApiHelper.initRbmApi(privateKey);

// The RBM API can now be initialised to use a specific regional
// entry point.
// rbmApiHelper.initRbmApi(privateKey, rbmApiHelper.REGION_APAC);
// rbmApiHelper.initRbmApi(privateKey, rbmApiHelper.REGION_EU);
// rbmApiHelper.initRbmApi(privateKey, rbmApiHelper.REGION_US);

发送附有建议的答复和行动的短信

// Create the payload for sending a message of "Hello, World!" along with
// a suggested reply and two suggested actions
rbmApiHelper.sendMessage({
  messageText: 'Hello, World!',
  msisdn: phoneNumber,
  suggestions: [
      {
        reply: {
          text: 'Sample Chip',
          postbackData: 'sample_chip',
        },
      },
      {
        action: {
          text: 'URL Action',
          postbackData: 'url_action',
          openUrlAction: {
            url: 'https://www.google.com',
          },
        },
      },
      {
        action: {
          text: 'Dial Action',
          postbackData: 'dial_action',
          dialAction: {
            phoneNumber: '+12223334444',
          },
        },
      },
    ]
  }
);

发一张富豪卡

// Create the payload for sending a rich card
rbmApiHelper.sendRichCard({
  messageText: 'Hello, world!',
  messageDescription: 'RBM is awesome!',
  msisdn: phoneNumber,
  suggestions: [
    {
      reply: {
         'text': 'Suggestion #1',
         'postbackData': 'suggestion_1',
      },
    },
    {
      reply: {
         'text': 'Suggestion #2',
         'postbackData': 'suggestion_2',
      },
    },
  ],
  imageUrl: 'http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif',
  height: 'TALL',
});
// Create the payload for sending a carousel
rbmApiHelper.sendCarouselCard({
  msisdn: phoneNumber,
  cardContents: [
    {
      title: 'Card #1',
      description: 'The description for card #1',
      suggestions: [
         {
            reply: {
               text: 'Card #1',
               postbackData: 'card_1',
            }
         }
      ],
      media: {
         height: 'MEDIUM',
         contentInfo: {
            fileUrl: 'https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg',
            forceRefresh: false,
         },
      },
    },
    {
      title: 'Card #2',
      description: 'The description for card #2',
      suggestions: [
         {
            reply: {
               text: 'Card #2',
               postbackData: 'card_2',
            }
         }
      ],
      media: {
         height: 'MEDIUM',
         contentInfo: {
            fileUrl: 'https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg',
            forceRefresh: false,
         },
      },
    },
});

发送带有生命时间的信息

发送按成果管理信息,如果时间已到,将取消 在交付之前 已添加至第1.0.3版.

const params = {
  messageText: 'This message will expire!',
  msisdn: config.phoneNumber,
  // allow 10 seconds for message delivery
  timeToLive: '10s',
};

rbmApiHelper.sendMessage(params,
  function(response, err) {
    if (err !== undefined) {
      console.log(
        util.inspect(err, {showHidden: false, depth: null, colors: true}));
    }
    if (response !== undefined) {
      console.log(
        util.inspect(response, {showHidden: false, depth: null, colors: true}));
    }
  }
);

用过期时间发送信件

发送将取消的成果管理制消息,如果到期时间已到 在交付之前 已添加至第1.0.3版.

// Calculate UTC time in zulu format 20 seconds from now
const d = new Date();

d.setSeconds(d.getSeconds()+20);

const params = {
  messageText: 'This message will expire!',
  msisdn: config.phoneNumber,
  expireTime: d.toISOString()
};

rbmApiHelper.sendMessage(params,
  function(response, err) {
    if (err !== undefined) {
      console.log(
        util.inspect(err, {showHidden: false, depth: null, colors: true}));
    }
    if (response !== undefined) {
      console.log(
        util.inspect(response, {showHidden: false, depth: null, colors: true}));
    }
  }
);

上传文件到 RMB 内容存储

支持在发布1.0.6.中添加文件上传.

const params = {
  fileUrl: 'https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg',
  thumbnailUrl: 'https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg',
  // contentDescription: string
};

rbmApiHelper.uploadFile(params,
  function(response, err) {
    if (err !== undefined) {
      console.log(
        util.inspect(err, {showHidden: false, depth: null, colors: true}));
    }
    if (response !== undefined) {
      console.log(
        util.inspect(response, {showHidden: false, depth: null, colors: true}));
    }
  }
);

发送先前上传的文件

第1.0.6.版中增加了支持内容.

const params = {
  // Uploaded file id. If this uplod also contains a thumbnail, it will be used
  uploadedFileName: 'files/lpcg6f1tnYg1ryaQNho6hjka',
  // Uploaded thumbnail id. If this upload contains a thumbnail then it will be
  // used in preference to the one above.
  // uploadedThumbnailName: "files/lpchblt9boYTjT8ck6UGQ8uK",
  msisdn: config.phoneNumber,
};

rbmApiHelper.sendMessage(params,
  function(response, err) {
    if (err !== undefined) {
      console.log(
        util.inspect(err, {showHidden: false, depth: null, colors: true}));
    }
    if (response !== undefined) {
      console.log(
      util.inspect(response, {showHidden: false, depth: null, colors: true}));
    }
  }
);

版本

这个图书馆跟随 语义版本。 。 。 .

这个图书馆被认为是 一般可用性(GA)这表示 稳定; 代码表面不会改变向后兼容的方式 除非绝对必要(例如,由于关键的安全问题)或 大量贬值期。 问题和要求 大会 图书馆 以最高优先处理.

捐款

欢迎捐款! 见 贡献指南。 。 。 .

许可证

Apache 版本 2.0

见 自由主义

已知问题

在最近版本的节点.js上,您可能看到这个贬值警告:

(node:23043) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

这是因为在基本法律中存在依赖性 googleapis 图书馆。 这事会解决的 当负责这个图书馆的团队 运送更新版.

版本与发布记录

@google/rcsbusinessmessaging 共发布 8 个版本,首次发布于 2023/12/06;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.10latest2024/08/142 年前
1.0.92024/07/302 年前
1.0.82024/06/042 年前
1.0.72023/12/092 年前
1.0.62023/12/082 年前
1.0.52023/12/082 年前

关于 @google/rcsbusinessmessaging 的常见问题

@google/rcsbusinessmessaging 是什么?

RCS 商务信件 API 的节点帮助库

如何安装 @google/rcsbusinessmessaging?

在项目目录运行 npm install @google/rcsbusinessmessaging,或使用 pnpm add / yarn add / bun add。

@google/rcsbusinessmessaging 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/google__rcsbusinessmessaging 是否存在。

@google/rcsbusinessmessaging 支持 ESM 还是 CommonJS?

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

@google/rcsbusinessmessaging 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18.18.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@google/rcsbusinessmessaging 可以商用吗?

@google/rcsbusinessmessaging 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@google/rcsbusinessmessaging 的下载量有多少?

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

@google/rcsbusinessmessaging 还在维护吗?

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