D
D
Dimash Kenzhegaliev2021-02-02 00:56:22
Node.js
Dimash Kenzhegaliev, 2021-02-02 00:56:22

How to pass arguments to action function via callback_data in telegraf js?

you need to pass input parameters to bot.action via callback_data

bot.hears('all users chat with phone number', async (ctx) => {
      const allChats = await mongoMessages.find().exec()
      const keyboardArray = new Array()
      allChats.forEach(chat => {
        keyboardArray.push([ { text: `${chat.userName}: ${chat.phoneNumber}`, callback_data: `findUserByPhoneNumber` } ])
      }),
      ctx.reply('all users:', {
        reply_markup: {
          inline_keyboard: keyboardArray
        }
      })
    })

    bot.action('findUserByPhoneNumber', async (ctx) => {
      console.log(ctx)
      const chat = await mongoMessages.find({ phoneNumber: ctx.message.text }).exec()
      ctx.reply(chat)
    })


plz help i'm really screwed

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question