A
A
archileva2022-04-10 20:02:42
Telegram
archileva, 2022-04-10 20:02:42

Telegram bot js, how to make a test using a bot?

How are tests created on js for a telegram bot?
i write this code

const testQuest1 = {
    reply_markup:JSON.stringify({
        inline_keyboard:[
            [{text:"Да",callback_data:11},{text:"нет",callback_data:12}]
        ]
    })
}


const startTest = async(chatId) =>{
    await bot.sendMessage(chatId,"У тебя часто нет аппетита?",testQuest1)
}
const startTest2 =async(chatId) =>{
    await bot.sendMessage(chatId,"У тебя часто усталость утром?",testQuest1)
}

const start = () =>{
    bot.setMyCommands([
        {command:"/start",description:"Приветствие "}, 
        {command:"/info",description:"Напомнить твое имя и фамилию."},
        {command:"/game",description:"сыграть в игру."},
        {command:"/test",description:"пройти тест."},
    ])
    
    bot.on("message",async msg =>{
    const text = msg.text;
    const chatId = msg.chat.id;
    
  
    if(text === "/start"){
        await bot.sendSticker(chatId,"https://tlgrm.ru/_/stickers/5a7/cb3/5a7cb3d0-bca6-3459-a3f0-5745d95d54b7/1.jpg")
        return bot.sendMessage(chatId,`Привет,я бот с помощью которого ты можешь пройти тест!`);
    }
    if(text === "/info"){
        return  bot.sendMessage(chatId,`Тебя зовут ${msg.from.first_name} ${msg.from.last_name} `);
        }
   
    if(text ==="/test"){
        return startTest(chatId)
    }
    })   
 bot.on("callback_query",msg =>{
        const data = msg.message.chat.id;
        if(data)
            return startTest2;
        
    })
 

  
}
start();

How can I make it so that after the appearance of startTest, by clicking on one of the buttons, startTest2 appears and the choice between yes / no buttons is remembered somewhere?
to shove them into some array?
but how exactly, at the moment for telegram bots I don’t understand much, tell me please.

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