3

I'm trying to create a telegram bot using telegraf

I read its documentation and I just wanted to start coding using their own examples

this is the example provided in documentation:

const { Telegraf } = require('telegraf')

const bot = new Telegraf(process.env.BOT_TOKEN)
bot.start((ctx) => ctx.reply('Welcome'))
bot.help((ctx) => ctx.reply('Send me a sticker'))
bot.on('sticker', (ctx) => ctx.reply(''))
bot.hears('hi', (ctx) => ctx.reply('Hey there'))
bot.launch()

// Enable graceful stop
process.once('SIGINT', () => bot.stop('SIGINT'))
process.once('SIGTERM', () => bot.stop('SIGTERM'))

when i try to run the code,i get the following error:

TypeError: Object.fromEntries is not a function error screenshot

PS: I have got my BOT_TOKEN from BotFather and placed it in the .env

thanks in advance

amir yeganeh
  • 647
  • 3
  • 11
  • 23

3 Answers3

3

It seems you are using old version of node.js that do not support Object.fromEntries

Just update it to at least 12 version

coop
  • 31
  • 1
3

there are some issues with the new version of telegraf.

i currently use version 3.38.0 and it works just fine.

1

Which version of telegraf are you using?

They updated it recently, still some bugs are not cleared. Remove telegraf, and install 3.38th version, and try to launch again. If won't work, then something is wrong with your configuration.

Tigran Petrosyan
  • 524
  • 4
  • 14