You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Telegraf.js实现Telegram用户输入框预填充文本可行性问询

可以用Telegraf.js实现该功能

你可以通过Telegraf.js结合Telegram Bot API的switch_inline_query_current_chat参数,实现点击按钮或触发命令后将模板文本填充到用户输入框的效果,具体实现方式如下:

实现步骤与代码示例

  • 创建Telegraf实例并配置机器人令牌
  • 处理命令或按钮交互,返回带有Inline键盘的消息,通过switchToCurrentChat方法指定要填充的模板文本
const { Telegraf, Markup } = require('telegraf');
const bot = new Telegraf('你的机器人令牌');

// 处理命令触发模板填充
bot.command('gettemplate', (ctx) => {
  // 定义目标模板文本
  const textTemplate = `Project:
Priority:
Etc.`;
  // 发送带触发按钮的消息
  return ctx.reply('点击按钮填充模板到输入框', Markup.inlineKeyboard([
    Markup.button.switchToCurrentChat('填充模板', textTemplate)
  ]));
});

// 启动机器人
bot.launch();

功能说明

用户发送/gettemplate命令后,机器人会推送一条带按钮的消息;用户点击按钮时,Telegram会自动将预设模板插入到当前聊天的输入框中,用户可直接编辑内容后发送。

内容的提问来源于stack exchange,提问作者pnrdr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 08:40:31