# @grammyjs/auto-chat-action 中文文档

规范地址：https://npmcn.com/package/%40grammyjs/auto-chat-action/

版本：0\.1\.1
npm 元数据更新时间：2025-03-01T13:34:11.256Z
中文译文更新时间：2026-11-17T06:41:29.528Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40grammyjs/auto-chat-action
原文对照：https://npmcn.com/package/%40grammyjs/auto-chat-action/?lang=original
项目主页：https://github.com/grammyjs/auto-chat-action#readme
源码仓库：https://github.com/grammyjs/auto-chat-action

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

- 包体积（解压后）：24 kB，29 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- peer 依赖：grammy ^1\.0\.0
- 首次发布：2023-02-07T20:38:36.520Z
- 最新版本发布：2023-03-27T15:29:09.062Z
- 近 30 天下载量：5542（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：3（近 12 个月 0 个）

## 中文简介

自动发送聊天动作的插件

## 安装

```sh
npm install @grammyjs/auto-chat-action
```

也可以使用：`pnpm add @grammyjs/auto-chat-action`、`yarn add @grammyjs/auto-chat-action`、`bun add @grammyjs/auto-chat-action`

## README

# GrammY 自动聊天动作插件

此插件提供了一个自动发送合适的中间软件 [聊天动作](https://core.telegram.org/bots/api#sendchataction)。 。 。 .  
例如,当 `sendVideo` 名为.

## 安装

### 节点

```sh
npm i @grammyjs/auto-chat-action
```

### 德诺

```ts
import { autoChatAction } from "https://deno.land/x/grammy_auto_chat_action/mod.ts";
```

### 安装插件

```ts
import {
  autoChatAction,
  AutoChatActionFlavor,
} from "@grammyjs/auto-chat-action";

// Extend the context
const bot = new Bot<Context & AutoChatActionFlavor>("");

// Install the plugin
bot.use(autoChatAction());
```

## 使用量

```ts
import { Bot, Context } from "grammy";
import {
  autoChatAction,
  AutoChatActionFlavor,
} from "@grammyjs/auto-chat-action";

type MyContext = Context & AutoChatActionFlavor;

// Create a bot.
const bot = new Bot<MyContext>("token");

// Install the plugin
bot.use(autoChatAction());

bot.command("start", (ctx) => {
  // Starts sending "typing" chat action in a loop
  ctx.chatAction = "typing";

  // Some long-running operations...

  return ctx.reply("42!");
});

bot.command("photo", (ctx) => {
  // Sending the "upload_photo" chat action until the media is uploaded
  return ctx.replyWithPhoto(
    new InputFile("/tmp/picture.jpg"),
  );
});

bot.start();
```

### 自动动作发送

自动发送聊天动作在下列条件下开始:

1.  从列表中请求方法 :
    -   发送图片
    -   发送奥迪奥
    -   发送文档
    -   发送视频
    -   发送动画
    -   发送声音
    -   发送视频注释
    -   发送Sticker
    -   发送媒体组
2.  请求有效载荷包含 [输入文件](https://grammy.dev/guide/files.html#uploading-your-own-files)
3.  请求有效载荷包含聊天ID.

发送聊天动作在下列条件下之一停止:

1.  更新处理完成 .
2.  需要聊天动作的请求完成 .
3.  `sendChatAction` 请求导致错误.

### 手动动作发送

#### 以上下文发送聊天动作

```ts
// Set the action to be sent until the update is processed
ctx.chatAction = "typing";

// To stop sending, simply set the chat action to null
ctx.chatAction = null;

// You can change the chat action during update processing
ctx.chatAction = "choose_sticker";
```

发送需要发送聊天动作的其他请求将中断 发送当前聊天动作 .

```ts
ctx.chatAction = "typing";

await ctx.reply("Hi!");

// Sends "upload_photo" while file is uploading
await ctx.replyWithPhoto(
  new InputFile("/tmp/kitten.png"),
);

// Now there is no sending chat action
// ctx.chatAction is null
```

#### 用中间软件发送聊天动作

```ts
import { chatAction } from "@grammyjs/auto-chat-action";

bot.command("start", chatAction("typing"), (ctx) => {
  // Some long-running operations...

  return ctx.reply("42!");
});
```

#### 使用方式 [对话](https://grammy.dev/plugins/conversations)

你得通过 `bot.api` 明确使用带有对话的插件.

```ts
// Pass API instance to the plugin
bot.use(autoChatAction(bot.api));

async function greeting(conversation: Conversation<Context>, ctx: Context) {
  await ctx.reply("Hi there! What is your name?");

  const { message } = await conversation.wait();
  ctx.chatAction = "typing";
  await conversation.sleep(1000);
  await ctx.reply(`Welcome to the chat, ${message.text}!`);
}
```

## 常见问题

### @grammyjs/auto-chat-action 是什么？

自动发送聊天动作的插件

### 如何安装 @grammyjs/auto-chat-action？

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

### @grammyjs/auto-chat-action 支持 TypeScript 吗？

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

### @grammyjs/auto-chat-action 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @grammyjs/auto-chat-action 可以商用吗？

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

### @grammyjs/auto-chat-action 的下载量有多少？

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

### @grammyjs/auto-chat-action 还在维护吗？

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

