skip to Main Content

Simple usage works fine:

const { Telegraf } = require('telegraf');
const bot = new Telegraf(tgBotToken);
bot.telegram.sendMessage(tgChatId, "My message");

But if I want to use HTML in my message, I need to require telegraf/extra

const { Telegraf } = require('telegraf');
const tgExtra = require('telegraf/extra');

But I get an error:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './extra' is not defined by "exports" in C:MyProjectnode_modulestelegrafpackage.json

Telegraf was installed via npm install telegraf. Running npm install telegraf/extra leads to trying to install non-existing package.

Is there any trick of installing something extra for… extra?

2

Answers


  1. If you are using Telegraf V4 . As there changelog says , Extra has been entirely removed in V4 .

    Extra is removed entirely, see #1076.

    You can now just specify any options directly, without having to create an Extra instance before

    Login or Signup to reply.
  2. In Telegraf V4, the Extra now is inside if the ‘telegraf’.

    Example:

    const { Telegraf, Markup } = require('telegraf');
    
    const bot = new Telegraf(tgBotToken);
    bot.on('message', async ctx => {
        ctx.replyWithHTML(tgChatId, "My message", Markup.button.url('Button Name', 'https://you.url'));
    })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search