1

So on the Telegraf api they have this example.

const Telegraf = require('telegraf')
const express = require('express')

const bot = new Telegraf(process.env.BOT_TOKEN)

bot.on('text', ({ replyWithHTML }) => replyWithHTML('<b>Hello</b>'))

bot.telegram.setWebhook('https://----.localtunnel.me/secret-path')

const app = express()
app.get('/', (req, res) => res.send('Hello World!'))

app.use(bot.webhookCallback('/secret-path'))
app.listen(3000, () => {
  console.log('Example app listening on port 3000!')
})

And it clearly work fine because i can see that i get post requests on /secret-path route.

But what i don't understand is how do i work with those requests. As far as i understand how this is working is that app.use(bot.webhookCallback('/secret-path')) creates this route in my express app.

Anyway, the question is, how do i work with requests that come to this route e.g. if i want to console.log request.body and so on.

Eugene Ganshin
  • 125
  • 1
  • 10

1 Answers1

2

The solution seems to be in this function. If body-parser.json() is used.

app.post(`/secret-path`, (req, res) => {
    console.log(req.body)
    return bot.handleUpdate(req.body, res)
})

Correct me if i'm wrong.

Eugene Ganshin
  • 125
  • 1
  • 10