Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document roziscoding/grammy-autoquote #441

Merged
merged 17 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions site/docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ export default defineUserConfig({
text: "Useful Middleware",
link: "/plugins/middlewares.html",
},
{
text: "Autoquote",
link: "/plugins/autoquote.html",
},
{
text: "[Submit your PR!]",
link: "/plugins/#submitting-your-own-package-to-the-docs",
Expand Down
56 changes: 56 additions & 0 deletions site/docs/plugins/autoquote.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Always replying to messages
roziscoding marked this conversation as resolved.
Show resolved Hide resolved

Sometimes, especially for bots that are meant to be used in groups, it is necessary to always send messages as a reply (or quote) to the message that started the interaction. Usually, the way to do that is to mannualy add `reply_to_message_id` to the params of the mathod that sends the message (`sendText` / `reply`, `sendPhoto` / `replyWithPhoto`). However, if you're doing this for every message, it can get a bit messy and tiring.
roziscoding marked this conversation as resolved.
Show resolved Hide resolved

This plugin sets the value of `reply_to_message_id` param to `ctx.msg.message_id` for every `send` method (except for `sendChatAction`, which does not support this parameter), thus making every message a reply to the message that triggered that update.
roziscoding marked this conversation as resolved.
Show resolved Hide resolved

## Usage

### For a single route
roziscoding marked this conversation as resolved.
Show resolved Hide resolved

Use this if you want all messages sent from within a specific context (like a specific command) to
roziscoding marked this conversation as resolved.
Show resolved Hide resolved

```ts
import { Bot } from "grammy";
import { addReplyParam } from "@roziscoding/grammy-autoquote";
// import { addReplyParam } from 'https://deno.land/x/grammy_autoquote/mod.ts'
roziscoding marked this conversation as resolved.
Show resolved Hide resolved

const bot = new Bot("");

bot.command("demo", async (ctx) => {
ctx.api.config.use(addReplyParam(ctx));
ctx.reply("Demo command!"); // This will quote the user's message
KnorpelSenf marked this conversation as resolved.
Show resolved Hide resolved
});

bot.start();
```

### Usage for every route
roziscoding marked this conversation as resolved.
Show resolved Hide resolved

Use this if you want absolutelly every possible message sent from your bot to quote the triggering message.
roziscoding marked this conversation as resolved.
Show resolved Hide resolved

```ts
import { Bot } from "grammy";
import { autoQuote } from "@roziscoding/grammy-autoquote";
// import { autoQuote } from 'https://deno.land/x/grammy_autoquote/mod.ts'

const bot = new Bot("");

bot.use(autoQuote);

bot.command("demo", async (ctx) => {
ctx.reply("Demo command!"); // This will quote the user's message
KnorpelSenf marked this conversation as resolved.
Show resolved Hide resolved
});

bot.command("hello", async (ctx) => {
ctx.reply("Hi there :)"); // Also quotes the user's message
KnorpelSenf marked this conversation as resolved.
Show resolved Hide resolved
});

bot.start();
```

## Plugin Summary

- Name: Autoquote
- Source: <https://github.com/roziscoding/grammy-autoquote>
- Reference: <https://doc.deno.land/https://deno.land/x/grammy_autoquote/mod.ts>
roziscoding marked this conversation as resolved.
Show resolved Hide resolved