Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
297 views
in Technique[技术] by (71.8m points)

telegraf - Randomeading Nodejs telegraph json

using a telegraph button I coded with nodejs, I want it to send the names available in the json randomly to the user whenever I press the button. How can I do that?

question from:https://stackoverflow.com/questions/65882691/randomeading-nodejs-telegraph-json

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You could shuffle your json object whenever your button is pressed. And the previous message gets deleted. This would be done like this:

bot.action('callback_data', (ctx) => {
     ctx.deleteMessage()
     var json
     // Shuffle json

     ctx.telegram.sendMessage(ctx.chat.id, `${json}`, {
        reply_markup: {
           inline_keyboard: [
               [{text: "Settle", callback_data: "callback_data"}]
           ]
        }
    })
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...