Skip to main content

Auto quote plugin for grammY

JSR JSR Score

This plugin provides a convenient way to quote the user’s message when replying to them.

How does it work

This plugin works by setting reply_to_message_id param to the value of ctx.msg.message_id for every API method that starts with send (except for sendChatAction).

Installation

Deno

Just import the plugin from jsr:

import { autoQuote } from "jsr:@roz/grammy-autoquote";

Or add an import map and import it directly

deno add @roz/grammy-autoquote
import { autoQuote } from "@roz/grammy-autoquote";

Node.js

Add the plugin to your project

  • jsr (preferred)

    npx jsr add @roz/grammy-autoquote
  • npm

    npm install @roziscoding/grammy-autoquote

Then import it in your code

import { autoQuote } from "@roz/grammy-autoquote"; // for jsr
import { autoQuote } from "@roziscoding/grammy-autoquote"; // for npm

Usage

Reply Parameters

The plugin supports specifying the allow_send_without_reply parameter, which will allow the bot to send messages without quoting the user’s message. To do so, just pass an object to the plugin initializer like so:

autoQuote({ allow_send_without_reply: true });

For a single context

import { Bot } from "grammy";
import { addReplyParam } from "@roz/grammy-autoquote";

const bot = new Bot("");

bot.command("demo", async (ctx) => {
  ctx.api.config.use(addReplyParam(ctx));
  // ctx.api.config.use(addReplyParam(ctx, { allow_send_without_reply: true }));

  ctx.reply("Demo command!"); // This will quote the user's message
});

bot.start();

For every context

import { Bot } from "grammy";
import { autoQuote } from "@roz/grammy-autoquote";

const bot = new Bot("");

bot.use(autoQuote());
// bot.use(autoQuote({ allow_send_without_reply: true })

bot.command("demo", async (ctx) => {
  ctx.reply("Demo command!"); // This will quote the user's message
});

bot.command("hello", async (ctx) => {
  ctx.reply("Hi there :)"); // Also quotes the user's message
});

bot.start();