# @google/rcsbusinessmessaging 中文文档

规范地址：https://npmcn.com/package/%40google/rcsbusinessmessaging/

版本：1\.0\.10
npm 元数据更新时间：2025-04-30T16:44:00.722Z
中文译文更新时间：2026-11-16T20:02:42.843Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40google/rcsbusinessmessaging
原文对照：https://npmcn.com/package/%40google/rcsbusinessmessaging/?lang=original
项目主页：https://github.com/rcs-business-messaging/rbm-api-examples#readme
源码仓库：https://github.com/rcs-business-messaging/rbm-api-examples

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：145 kB，8 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- Node.js 要求：\>=18\.18\.0
- 运行依赖：3 个
- 首次发布：2023-12-06T15:55:17.540Z
- 最新版本发布：2024-08-14T07:26:51.532Z
- 近 30 天下载量：133337（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：8（近 12 个月 0 个）

## 中文简介

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

## 安装

```sh
npm install @google/rcsbusinessmessaging
```

也可以使用：`pnpm add @google/rcsbusinessmessaging`、`yarn add @google/rcsbusinessmessaging`、`bun add @google/rcsbusinessmessaging`

## README

# [Google的RCS业务消息:Node.js客户端](https://github.com/rcs-business-messaging/rbm-api-examples/tree/master/nodejs/rbm-api-helper)

[RCS 业务消息](https://developers.google.com/business-communications/rcs-business-messaging/guides/get-started/how-it-works) 以品牌,丰富的媒体,互动,分析等手段升级短信. 有了RCS,企业可以将品牌,互动的移动体验带入本地的Android短信应用.

本文件载有: [API 参考](https://developers.google.com/business-communications/rcs-business-messaging/reference/rest),样品,以及开发Node.js应用的其他资源. 需要额外帮助开发RCS BusinessMessaging应用程序,使用Node.js和其他语言,参见我们 [RCS 商业消息快速启动](https://developers.google.com/business-communications/rcs-business-messaging/guides/get-started/first-agent) 向导.

## 文档

RCS 业务通讯 API 的文档可以找到 [这里](https://developers.google.com/business-communications/rcs-business-messaging/reference/rest)。 。 。 .

## 快速启动

### 在你开始之前

1.  [与 RCS 业务通讯注册](https://developers.google.com/business-communications/rcs-business-messaging/guides/get-started/register-partner)。 。 。 .

### 添加依赖关系

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

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

我们建议您使用最新版本 输入 [npm 仓库](https://www.npmjs.com/package/@google/rcsbusinessmessaging)。 。 。 .

## 样本使用情况

以下样本假设一个类似的库初始化,如 [使用客户端库](https://github.com/rcs-business-messaging/rbm-api-examples/tree/master/nodejs/rbm-api-helper#using-the-client-library) 节.

### 初始化

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

```javascript
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 myrbmagent@rbm.goog
```

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

```javascript
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);
```

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

```javascript
// 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',
          },
        },
      },
    ]
  }
);
```

### 发一张富豪卡

```javascript
// 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',
});
```

### 送木马

```javascript
// 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版.

```javascript
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版.

```javascript
// 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.中添加文件上传.

```javascript
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.版中增加了支持内容.

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

## 版本

这个图书馆跟随 [语义版本](http://semver.org/)。 。 。 .

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

## 捐款

欢迎捐款! 见 [贡献指南](https://github.com/rcs-business-messaging/rbm-api-examples/blob/master/CONTRIBUTING.md)。 。 。 .

## 许可证

Apache 版本 2.0

见 [自由主义](https://github.com/rcs-business-messaging/rbm-api-examples/blob/master/LICENSE)

## 已知问题

在最近版本的节点.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 是什么？

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 和提交记录判断。

