Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

220
Visualizações
send inline keyboard after all reply messages telegram/telegraf

I'm using telegraf library to create a Telegram bot that would send gif messages upon request. I use inline keyboard for this and when i press an option of gif message to be received i need to await API response, receive 2-3 gifs and show inline keybord again for next choice. The problem is that the inline keyboard is shown right after the option choice and it is not waiting for all the response messages. Tried to use call back functions and settimeout but the first option didn't work, the second option is not good because you never know how long to wait for the messages to be loaded on a device. Any suggestions?

bot.start(ctx => sendOptionsKeyboard(ctx, bot, 'What  shall I send you today? 😀' ))

bot.action('dog', ctx => showSpecificGif(ctx, bot))
bot.action('cat', ctx => showSpecificGif(ctx, bot))
const sendOptionsKeyboard = (ctx, bot, questionMessage) => {
  bot.telegram.sendMessage(ctx.chat.id, questionMessage, {
    reply_markup: {
      inline_keyboard: [
        [
          { text: 'show dogs', callback_data: 'dog' },
          { text: 'show cats', callback_data: 'cat' },
        ]
      ],
    },
  })
}

const showSpecificGif = async (ctx, bot) => {
  try {
    ctx.reply('Loading...🤔')
    const offset = Math.floor(Math.random() * 4500)
    const res = await axios.get(
      `https://api.giphy.com/v1/gifs/search?api_key=${process.env.GIPHY_API_KEY}&q=${ctx.update.callback_query.data}&limit=3&offset=${offset}&rating=g&lang=en`
    )
    const gifArray = res.data.data
    gifArray.forEach(gif => ctx.replyWithVideo(gif.images.downsized_medium.url))
  } catch (err) {
    ctx.reply('You got error')
  }
    sendOptionsKeyboard(ctx, bot, 'Send again? 😀')
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda