jeudi 23 novembre 2017

Random functions with inline mode in Telegram

I want to return a random string from a list I created using the inline mode in Telegram.

'use strict'

const Telegraf = require('telegraf')
const bot = new Telegraf('TOKEN')

const quotes = {
"1" : "Do you like laundry detergent?",
"2" : "Bird up! The worst show on television",
"3" : "Jump down"
}

bot.on('inline_query', (ctx) => {

  ctx.answerInlineQuery([
    {
        type: "article",
        id: "Gay",
        title: "Have you seen CHEF?",
        description: "I have crippling depression",
        thumb_url: "http://ift.tt/2A2uk7h",
        input_message_content: {
        message_text: quotes[Math.floor((Math.random() * 3) + 1).toString()]
    }
    }])
})
bot.startPolling()

I'm not familiar with cached data. I tried using:

console.log(ctx.message)

and

console.log(ctx.query)

to determine what information to use but I only get "undefined". I want to take the input from the user to use it in my code.

All I want to achieve is to have a code word like "Random" and able to get a random string every time. I don't need to save any data from the user.

Telegram inline mode API




Aucun commentaire:

Enregistrer un commentaire