“ReferenceError:标记未定义”错误

问题描述 投票:0回答:1

我想让我的电报机器人自动回复带有描述的图像的用户消息。我还想添加 url 内联按钮,将用户重定向到特定网站。

代码:

const { Telegraf, Extra } = require("telegraf");
const bot = new Telegraf('my bot token');
bot.on('text', async (ctx) => {
  const message = `Test Message`;

  const imageUrl = 'https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.bbc.com%2Fnews%2Fworld-us-canada-37493165&psig=AOvVaw0d_XITsiMbIX2n-18x9DGF&ust=1693310036962000&source=images&cd=vfe&opi=89978449&ved=0CBAQjRxqFwoTCMjv8sul_4ADFQAAAAAdAAAAABAE';
  const caption = message;
  const urlButton = Markup.inlineKeyboard([
    Markup.urlButton('Example Button', 'www.google.com'),
  ]);
});

bot.launch();
console.log('Bot Online!')


当用户单击内联按钮时,机器人会将错误发送到控制台。

错误:

/home/runner/chatgpt-bot-telegram/index.js:38
  const urlButton = Markup.inlineKeyboard([
                    ^

ReferenceError: Markup is not defined
    at /home/runner/chatgpt-bot-telegram/index.js:38:21
    at /home/runner/chatgpt-bot-telegram/node_modules/telegraf/lib/composer.js:167:111
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async execute (/home/runner/chatgpt-bot-telegram/node_modules/telegraf/lib/composer.js:485:17)
    at async /home/runner/chatgpt-bot-telegram/node_modules/telegraf/lib/composer.js:486:21
    at async execute (/home/runner/chatgpt-bot-telegram/node_modules/telegraf/lib/composer.js:485:17)

Node.js v18.12.1
repl process died unexpectedly: exit status 1
node.js telegram-bot telegraf referenceerror
1个回答
0
投票

您需要从

Markup
库导入
telegraf

const { Telegraf, Extra, Markup } = require("telegraf");
© www.soinside.com 2019 - 2024. All rights reserved.