I want to make my telegram bot automatically reply user message with Image with description.I also want to add url inline button that redirect user to specific website.
Code:
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!')
When user click the inline button, bot send error to console.
Error:
/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
You need to import Markup
from the telegraf
library.
const { Telegraf, Extra, Markup } = require("telegraf");