-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Ciki Momogi <git.fytyt@aleeas.com> Co-authored-by: WingLim <643089849@qq.com> Co-authored-by: Rogerio Jurado Munhoz <rogerio.munhoz@macbook-will130867.local> Co-authored-by: KnorpelSenf <shtrog@gmail.com> Co-authored-by: Roj <ez@roj.im> Co-authored-by: Roz <3948961+roziscoding@users.noreply.github.com> Co-authored-by: Habemuscode <habemuscode@protonmail.com>
- Loading branch information
1 parent
daad7c4
commit 92563ba
Showing
5 changed files
with
453 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
# Responder siempre a los mensajes | ||
|
||
A veces es necesario enviar siempre los mensajes como respuestas, especialmente para los bots que están destinados a ser utilizados en grupos. | ||
Normalmente hacemos esto añadiendo el parámetro `reply_to_message_id` a los métodos que envían el mensaje: `sendText`, `reply`, `sendPhoto`, `replyWithPhoto` y otros. | ||
Sin embargo, si estás haciendo esto para cada mensaje, puede ser un desastre y aburrido. | ||
|
||
Este plugin establece el parámetro `reply_to_message_id` a `ctx.msg.message_id` para todos los métodos `reply*` y `send*` que lo soportan para hacer que cada mensaje sea una respuesta al mensaje que lo activó. | ||
|
||
## Uso | ||
|
||
### En Rutas Específicas | ||
|
||
Si quieres que todos los mensajes se envíen dentro de un contexto específico (como un comando específico), puedes aplicar el plugin específicamente a ellos: | ||
|
||
<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("¡Comando demo!"); // esto va a citar el mensaje del usuario | ||
}); | ||
|
||
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("¡Comando demo!"); // esto va a citar el mensaje del usuario | ||
}); | ||
|
||
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("¡Comando demo!"); // esto va a citar el mensaje del usuario | ||
}); | ||
|
||
bot.start(); | ||
``` | ||
|
||
</CodeGroupItem> | ||
</CodeGroup> | ||
|
||
### Para todas las rutas | ||
|
||
Si quieres que todos los mensajes enviados respondan a los mensajes que los desencadenaron, puedes aplicar el plugin de esta manera: | ||
|
||
<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("¡Comando demo!"); // esto va a citar el mensaje del usuario | ||
}); | ||
|
||
bot.command("hola", async (ctx) => { | ||
await ctx.reply("Hola :)"); // esto también cita el mensaje del usuario | ||
}); | ||
|
||
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("¡Comando demo!"); // esto va a citar el mensaje del usuario | ||
}); | ||
|
||
bot.command("hola", async (ctx) => { | ||
await ctx.reply("Hola :)"); // esto también cita el mensaje del usuario | ||
}); | ||
|
||
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("¡Comando demo!"); // esto va a citar el mensaje del usuario | ||
}); | ||
|
||
bot.command("hola", async (ctx) => { | ||
await ctx.reply("Hola :)"); // esto también cita el mensaje del usuario | ||
}); | ||
|
||
bot.start(); | ||
``` | ||
|
||
</CodeGroupItem> | ||
</CodeGroup> | ||
|
||
## Resumen del plugin | ||
|
||
- Nombre: Autoquote | ||
- Fuente: <https://github.com/roziscoding/grammy-autoquote> | ||
- Referencia de la API: <https://doc.deno.land/https://deno.land/x/grammy_autoquote/mod.ts> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
- API Reference: <https://doc.deno.land/https://deno.land/x/grammy_autoquote/mod.ts> |
Oops, something went wrong.