Telegraph JS simple button with markup not working

156 Views Asked by At

I am tying to build a telegram bot using telegrafJS library on a node typescript project.

I want to create a simple button when a user types a command. I tried using examples from the documentation (from this question How to create messages with reply buttons). But it is not working. I have multiple ts errors:

  • Argument of type 'Markup & InlineKeyboardMarkup' is not assignable to parameter of type 'ExtraReplyMessage | undefined'.
  • Property 'callback' does not exist on type '(text: string, hide?: boolean | undefined) => Button'.

Here is my code:

import TelegrafJS from 'telegraf';

const { Markup } = TelegrafJS;

const { TELEGRAM_API_TOKEN } = process.env;
if (!TELEGRAM_API_TOKEN) throw new Error('Required env variable missing: TELEGRAM_API_TOKEN');

const bot = new TelegrafJS.Telegraf(TELEGRAM_API_TOKEN);

// WORKS
bot.command('test0', (ctx) => {
  ctx.reply('Test 0', {
    reply_markup: {
      inline_keyboard: [
        [{ text: 'Next', callback_data: 'next' }],
      ],
    },
  });
});

// NOT WORKING
bot.command('keyboard', (ctx) => ctx.reply(
  'Keyboard',
  Markup.inlineKeyboard([
    Markup.button.callback('First option', 'first'),
    Markup.button.callback('Second option', 'second'),
  ]),
));

bot.launch();

ts error telegraf button

It works without using Markup but I would prefer to use it. How Can I fix this errors ?

0

There are 0 best solutions below