V
V
vitland2019-10-21 18:31:46
JavaScript
vitland, 2019-10-21 18:31:46

How to make a request repeat button with current parameters?

Now there is a button that calls the function of choosing a random movie from the database by genre

bot.on('message', msg => {
      const chatId = helpers.getChatid(msg)
    switch (msg.text) {
        case kb.home.drama:
            sendFilmsByQuery(chatId, {type: 'Драма'})
            bot.sendMessage(chatId, 'Подбираем фильм', {
                reply_markup: { keyboard: keyboard.film }
            })
            break

function sendFilmsByQuery(chatId, query) {
  Film.find(query).then(films => {
//выбор случайного фильма из массива
      rndFilm = films[Math.floor(Math.random() * films.length)]

      const caption = `${rndFilm.name}
Год: ${rndFilm.year}
Кинопоиск: ${rndFilm.rate} 
${rndFilm.description}`

      bot.sendVideo(chatId, rndFilm.trailer, {
        caption: caption 
    }) 
})
}

How can I make the "next" button so that it restarts this part of the code?
rndFilm = films[Math.floor(Math.random() * films.length)]

      const caption = `${rndFilm.name}
      Год: ${rndFilm.year}
      Кинопоиск: ${rndFilm.rate}
      ${rndFilm.description}`

      bot.sendVideo(chatId, rndFilm.trailer, {
        caption: caption

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