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 14 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 @@ -250,6 +250,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
146 changes: 146 additions & 0 deletions site/docs/plugins/autoquote.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# 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 the `reply_to_message_id` parameter to the methods that send the message: `sendText`, `reply`, `sendPhoto`, `replyWithPhoto` and etc.
However, if you're doing this for every single message, it can get messy and boring.

This plugin sets the `reply_to_message_id` parameter to `ctx.msg.message_id` for all `reply*` and `send*` methods that support it to make every message a reply to the message that triggered it.

## Usage

### In Specific Routes

If you want all messages sent within a specific context (like a specific command), you can specifically apply the plugin to them:

<CodeGroup>
<CodeGroupItem title="TypeScript" active>

```ts
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();
```

</CodeGroupItem>
<CodeGroupItem title="JavaScript">

```js
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();
```

</CodeGroupItem>
<CodeGroupItem title="Deno">

```ts
import { Bot } from "https://deno.land/x/grammy/mod.ts";
import { addReplyParam } from "https://deno.land/x/grammy_autoquote/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();
```

</CodeGroupItem>
</CodeGroup>

### In for All Routes

If you want every sent message to reply the messages that triggered them, you can apply the plugin this way:

<CodeGroup>
<CodeGroupItem title="TypeScript" active>

```ts
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();
```

</CodeGroupItem>
<CodeGroupItem title="JavaScript">

```js
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();
```

</CodeGroupItem>
<CodeGroupItem title="Deno">

```ts
import { Bot } from "https://deno.land/x/grammy/mod.ts";
import { autoQuote } from "https://deno.land/x/grammy_autoquote/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();
```

</CodeGroupItem>
</CodeGroup>

## 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