如何在Telegram bot中制作调查表的命令序列?

时间:2018-03-10 18:51:05

标签: javascript node.js telegram telegram-bot

对于一个问题,我在以下代码中有80多个问题,我这样做但是没有用。如有任何帮助,我将不胜感激:

我正在使用telegraf SDK for bot:

问题:

1)Q1:很少我感觉良好。 (1分)   Q2:我总是感觉很好。 (2分)

app.action('Start', (ctx) => { 
//console.log(getdata('http://localhost:3000/api/questions'));
    getdata(myCallback);
});

var myCallback = function (data) {
    let i = Object.keys(data).length;
    let x = 0;
    for (x = 0;x!=i; x++ ){
        app.action(ctx => {
            ctx.editMessageText('Choose your own proper sentence:', Extra.HTML().markup(m => m.inlineKeyboard([
                m.callbackButton(data[x].Q1, 'plus1'),
                m.callbackButton(data[x].Q2, 'plus2')
            ])))
        });

    }
};
app.action('pluse1',(ctx)=>{
console.log(1);
//do somethings
});
app.action('pluse2', (ctx) => {
    console.log(2);
//do other things
});
var getdata = function (callback) {
    http.get('http://localhost:3000/api/questions', (res) => {
        res.setEncoding('utf8');
        let rawData = '';
        res.on('data', (chunk) => { rawData += chunk; });
        res.on('end', () => {
            try {
                const parsedData = JSON.parse(rawData);
                callback(parsedData);
            } catch (e) {
                console.error(e.message);
            }
        });
    }).on('error', (e) => {
        console.error(`Got error: ${e.message}`);
    });
}
function callback(data){
  console.log('cb',data)
    this.qa = data;
}

0 个答案:

没有答案