Telegraf: 'Hears' reply items

Created on 21 Feb 2018  ·  1Comment  ·  Source: telegraf/telegraf

Hey! I have menu as keyboard with button 'Items'. I want to render list of items, when user press 'Items' button on menu. For now, I tried this:

bot.start((ctx) => {
    console.log('Новый пользователь:', '@' + ctx.from.username, '(' + ctx.from.id + ')')
    return ctx.reply('Привет! Хочешь взять в краткосрочную аренду помещение?', Markup.keyboard([
            ['Items']
        ])
        .extra()
    )
})

bot.hears('Items', async ({answerInlineQuery}) => {
    let res = await axios.get('spaces')
    let data = res.data.spaces.map((space) => {
        const orderBtn = Markup.callbackButton('Заказать', 'order.' + space.id)

        return {
            type: 'article',
            id: space.id,
            title: space.title,
            description: `(${space.area_m}) : ${space.full_address}`,
            input_message_content: { message_text: 'Lol', parse_mode: 'Markdown' },
            reply_markup: Markup.inlineKeyboard([orderBtn]),
        }
    })

    if (res.data.status) {
        return answerInlineQuery(data)
    }
})

But it returns an error:
Error: Telegraf: "answerInlineQuery" isn't available for "message::text"

question

Most helpful comment

keyboard press produces not an inline query but just a text message that you need to process. It should be in ctx.update.message. And I think you should use ctx.reply to reply with a message.

>All comments

keyboard press produces not an inline query but just a text message that you need to process. It should be in ctx.update.message. And I think you should use ctx.reply to reply with a message.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bostrot picture bostrot  ·  3Comments

rozi98 picture rozi98  ·  3Comments

kuhel picture kuhel  ·  3Comments

aminjoharinia picture aminjoharinia  ·  3Comments

Stephirio picture Stephirio  ·  3Comments