# @2060\.io/credo-ts-didcomm-reactions 中文文档

规范地址：https://npmcn.com/package/%402060.io/credo-ts-didcomm-reactions/

版本：0\.1\.1
npm 元数据更新时间：2026-03-11T18:04:54.666Z
中文译文更新时间：2026-11-09T22:55:00.596Z
软件包许可：Apache-2\.0

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

原始 npm 页面：https://www.npmjs.com/package/%402060.io/credo-ts-didcomm-reactions
原文对照：https://npmcn.com/package/%402060.io/credo-ts-didcomm-reactions/?lang=original
项目主页：https://github.com/2060-io/credo-ts-didcomm-ext/tree/main/packages/reactions
源码仓库：https://github.com/2060-io/credo-ts-didcomm-ext

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

- 包体积（解压后）：39.4 kB，6 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：5 个
- peer 依赖：@credo-ts/core ^0\.6\.1，@credo-ts/didcomm ^0\.6\.1
- 首次发布：2025-03-11T21:37:14.610Z
- 最新版本发布：2026-03-11T18:04:54.393Z
- 近 30 天下载量：1703（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：5（近 12 个月 4 个）

## 中文简介

DIDComm 信件反应协议执行@ credo- ts/ core

## 安装

```sh
npm install @2060.io/credo-ts-didcomm-reactions
```

也可以使用：`pnpm add @2060.io/credo-ts-didcomm-reactions`、`yarn add @2060.io/credo-ts-didcomm-reactions`、`bun add @2060.io/credo-ts-didcomm-reactions`

## README

  
![Credo logo](https://github.com/openwallet-foundation/credo-ts/blob/c7886cb8377ceb8ee4efe8d264211e561a75072d/images/credo-logo.png)

# **DIDComm 信件反应协议的 Credo 扩展模块**

[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://raw.githubusercontent.com/openwallet-foundation/credo-ts-ext/main/LICENSE) [![typescript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](https://www.typescriptlang.org/) [![@2060.io/credo-ts-didcomm-reactions](https://img.shields.io/npm/v/@2060.io/credo-ts-didcomm-reactions)](https://www.npmjs.com/package/@2060.io/credo-ts-didcomm-reactions)

  

## 概览

这个 **信件反应** 扩展模块 [克里多语](https://github.com/openwallet-foundation/credo-ts) 使代理人能够管理 [反应协议](https://didcomm.org/reactions/1.0/),允许用户发送和接收对代理之间消息的emoji反应.

## 安装

```bash
npm install @2060.io/credo-ts-didcomm-reactions
```

## 使用量

### 将模块添加到您的代理

要使用反应模块,请添加到您的代理模块配置中:

```typescript
import { DidCommReactionsModule } from '@2060.io/credo-ts-didcomm-reactions'

const agent = new Agent({
  modules: {
    // ...other modules
    reactions: new DidCommReactionsModule(),
  },
})
```

### 发送信件反应

发送信息反应(如emoji反应或去除反应):

```typescript
const didcommReactions = [{ messageId: associatedMessageId ?? '', action: DidCommMessageReactionAction.React, emoji }]

// To remove a previous reaction:
didcommReactions.push({
  messageId: associatedMessageId ?? '',
  action: DidCommMessageReactionAction.Unreact,
  emoji: myPreviousReaction.emoji,
})

await agent.modules.reactions.send({
  connectionId: connection.id,
  reactions: didcommReactions,
})
```

您也可以针对动作发送反应 :

```typescript
if (action.type === AgentActionType.SendReaction) {
  const parameters = action.parameters as {
    didcommConnectionId: string
    didcommReactions: {
      messageId: string
      action: DidCommMessageReactionAction
      emoji: string
    }[]
  }

  const { didcommConnectionId, didcommReactions } = parameters

  return async (options: { agent: MobileAgent }) => {
    await options.agent.modules.reactions.send({
      connectionId: didcommConnectionId,
      reactions: didcommReactions,
    })
    return { outgoingMessageType: DidCommMessageReactionsMessage.type.messageTypeUri }
  }
}
```

### 处理反应事件

订阅反应事件以更新您的UI或消息存储, 当收到反应时 :

```typescript
import { MessageReactionsReceivedEvent } from '@2060.io/credo-ts-didcomm-reactions'

const messageReactionsReceivedListener = async (data: MessageReactionsReceivedEvent) => {
  const reactions = data.payload.reactions

  // Example: update message reactions in your store
  for (const reaction of reactions) {
    const relatedEntries = findAllByAssociatedMessageId(realm, reaction.messageId)
    for (const entry of relatedEntries) {
      const entryReactions = entry.reactions ? entry.reactions : []

      const reactionIndex = entryReactions.findIndex(
        (item) => item.role === ChatEntryRole.Receiver && item.emoji === reaction.emoji,
      )

      if (reaction.action === 'react' && reactionIndex === -1) {
        entryReactions.push({ emoji: reaction.emoji, role: ChatEntryRole.Receiver })
      }
      if (reaction.action === 'unreact' && reactionIndex !== -1) {
        entryReactions.splice(reactionIndex, 1)
      }
      entry.reactions = entryReactions
      entry.updatedAt = new Date().getTime()
    }
  }
}

// Subscribe to the event
agent.events.on('DidCommMessageReactionsReceived', messageReactionsReceivedListener)
```

## 特征

-   **发送信件反应**:以emojis对消息作出反应或去除反应.
-   **事件订阅**:倾听反应事件以更新UI或触发工作流程.
-   **协议整合**:与Credo代理和DIDComm协议的无缝集成.

## API 参考

见 [源代码](https://npmcn.com/package/%402060.io/credo-ts-didcomm-reactions/src/) 关于现有类别和方法的详细信息:

-   [`DidCommReactionsApi`](https://npmcn.com/package/%402060.io/credo-ts-didcomm-reactions/src/DidCommReactionsApi.ts): 主API用于发送反应.
-   [`DidCommReactionsService`](https://npmcn.com/package/%402060.io/credo-ts-didcomm-reactions/src/services/DidCommReactionsService.ts): 反应逻辑的内部服务.
-   [`DidCommReactionsModule`](https://npmcn.com/package/%402060.io/credo-ts-didcomm-reactions/src/DidCommReactionsModule.ts): Credo 代理的模块集成.

## 许可证

Apache 2.0 (英语)

* * *

更多信息,请参见 [克里多文档](https://github.com/openwallet-foundation/credo-ts.git)。 。 。 .

## 常见问题

### @2060\.io/credo-ts-didcomm-reactions 是什么？

DIDComm 信件反应协议执行@ credo- ts/ core

### 如何安装 @2060\.io/credo-ts-didcomm-reactions？

在项目目录运行 npm install @2060\.io/credo-ts-didcomm-reactions，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@credo-ts/core（^0\.6\.1）、@credo-ts/didcomm（^0\.6\.1）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @2060\.io/credo-ts-didcomm-reactions 支持 TypeScript 吗？

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

### @2060\.io/credo-ts-didcomm-reactions 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @2060\.io/credo-ts-didcomm-reactions 可以商用吗？

@2060\.io/credo-ts-didcomm-reactions 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @2060\.io/credo-ts-didcomm-reactions 的下载量有多少？

根据 npm 官方下载统计，@2060\.io/credo-ts-didcomm-reactions 在 2026/10/05 – 2026/11/03 这 30 天内被下载 1,703 次，日均约 57 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @2060\.io/credo-ts-didcomm-reactions 还在维护吗？

最新版本 0\.1\.1 发布于 2026/03/12（7 个月前）；至今共发布 5 个版本，其中过去 12 个月发布了 4 个；首次发布于 2025/03/12。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

