Always Replying to Messages
It is sometimes necessary to always send messages as replies, especially for bots that are meant to be used in groups. We usually do this by adding reply
to the methods that send the message: send
, reply
, send
, reply
and etc. However, if you’re doing this for every single message, it can get messy and boring.
This plugin sets the properties of reply
for all reply*
and send*
methods that support it to make every message a reply to the message and chat that triggered it.
You can pass an options object with a allow
property to both add
and auto
functions, which will allow your bot to send messages even if the message being replied to does not exist anymore.
Usage
In a Specific Context
If you want all messages sent within a specific context (like a specific command), you can specifically apply the plugin to them:
import { Bot } from "grammy";
import { addReplyParam } from "@roziscoding/grammy-autoquote";
const bot = new Bot("");
bot.command("demo", async (ctx) => {
ctx.api.config.use(addReplyParam(ctx));
await ctx.reply("Demo command!"); // this is going to quote the user's message
});
bot.start();
2
3
4
5
6
7
8
9
10
11
const { Bot } = require("grammy");
const { addReplyParam } = require("@roziscoding/grammy-autoquote");
const bot = new Bot("");
bot.command("demo", async (ctx) => {
ctx.api.config.use(addReplyParam(ctx));
await ctx.reply("Demo command!"); // this is going to quote the user's message
});
bot.start();
2
3
4
5
6
7
8
9
10
11
import { Bot } from "https://deno.land/x/grammy@v1.31.1/mod.ts";
import { addReplyParam } from "https://deno.land/x/grammy_autoquote@v2.0.8/mod.ts";
const bot = new Bot("");
bot.command("demo", async (ctx) => {
ctx.api.config.use(addReplyParam(ctx));
await ctx.reply("Demo command!"); // this is going to quote the user's message
});
bot.start();
2
3
4
5
6
7
8
9
10
11
In Every Context
If you want every sent message to reply the messages that triggered them, you can apply the plugin this way:
import { Bot } from "grammy";
import { autoQuote } from "@roziscoding/grammy-autoquote";
const bot = new Bot("");
bot.use(autoQuote());
bot.command("demo", async (ctx) => {
await ctx.reply("Demo command!"); // this is going to quote the user's message
});
bot.command("hello", async (ctx) => {
await ctx.reply("Hi there :)"); // this quotes the user's message, too
});
bot.start();
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const { Bot } = require("grammy");
const { autoQuote } = require("@roziscoding/grammy-autoquote");
const bot = new Bot("");
bot.use(autoQuote());
bot.command("demo", async (ctx) => {
await ctx.reply("Demo command!"); // this is going to quote the user's message
});
bot.command("hello", async (ctx) => {
await ctx.reply("Hi there :)"); // this quotes the user's message, too
});
bot.start();
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { Bot } from "https://deno.land/x/grammy@v1.31.1/mod.ts";
import { autoQuote } from "https://deno.land/x/grammy_autoquote@v2.0.8/mod.ts";
const bot = new Bot("");
bot.use(autoQuote());
bot.command("demo", async (ctx) => {
await ctx.reply("Demo command!"); // this is going to quote the user's message
});
bot.command("hello", async (ctx) => {
await ctx.reply("Hi there :)"); // this quotes the user's message, too
});
bot.start();
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Plugin Summary
- Name: Autoquote
- Source