GrammY 解析模式插件
该图书馆为难民署提供简化格式的公用设施 格莱姆Y 电报 瓶子框架. 它使您能够使用一个声明性,类型安全的 API 来编写内容丰富的格式化消息.
通过这个插件,您可以 :
- 使用已标记的模板文字和格式( 如粗体、 斜体、 链接等) 来构建格式化信件和标题
- 使用 fmt 函数对文本和媒体标题应用格式
该插件与Deno和Node.js都兼容,旨在作为需要强力格式化能力的grammY bots的滴入增强.
用法 (Using fmt) (英语)
import { Bot } from "grammy";
import { b, fmt, u } from "@grammyjs/parse-mode";
const bot = new Bot("");
bot.command("demo", async (ctx) => {
// Using return values of fmt
const combined = fmt`${b}bolded${b} ${ctx.msg.text} ${u}underlined${u}`;
await ctx.reply(combined.text, { entities: combined.entities });
await ctx.replyWithPhoto(photo, {
caption: combined.caption,
caption_entities: combined.caption_entities,
});
});
bot.start();
用法( 使用格式化 String)
import { Bot } from "grammy";
import { FormattedString } from "@grammyjs/parse-mode";
const bot = new Bot("");
bot.command("demo", async (ctx) => {
// Using return values of Fmt
const combined = FormattedString.b("bolded").plain(ctx.msg.text).u(
"underlined",
);
await ctx.reply(combined.text, { entities: combined.entities });
await ctx.replyWithPhoto(photo, {
caption: combined.caption,
caption_entities: combined.caption_entities,
});
});
bot.start();