Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

221
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda