聊天机器人一次询问所有问题

时间:2019-02-18 16:11:30

标签: javascript node.js methods response chatbot

我正在编写一个Slack Chatbot,并且试图创建一种方法,该方法可以在用户响应上一个问题时立即询问下一个问题。不幸的是,该方法一次都遍历了所有问题(在第一个问题之后)。

var status = { value: ' ' };

var ramCount = { value: 0 };
var HDDCount = { value: 0 };
var CPUCores = { value: 0 };

//Message handler
bot.on('message', (data) => {
    if(data.type !== 'message') return; //if data is not a message, exit     
    handleMessage(data.text, data.user);
});

//Intents
function handleMessage(message, user){
    if(message.includes(' make vm')){
        bot.postMessageToChannel('general', 'How much ram do you want your VM to have?');
        status.value = 'RAM';
        return;
    }

//RAM + HDD Question
reponse('RAM', 'HDD', ramCount, user, message, 'How much HDD do you want your VM to have?', 'general');

//HDD + CPU Question
reponse('HDD', 'CPU', HDDCount, user, message, 'How many cores do you want your VM to have?', 'general'); 

//CPU + OS Question 
reponse('CPU', 'OS', CPUCores, user, message, 'What OS do you want your vm to use?', 'general');
}

//Responses
function reponse(statusThis, statusNext, counter, user, userMessage, nextBotMessage, botChannel){
    if(userMessage.includes('<@UG82L6286> ') && user != null && status.value == statusThis){
    bot.postMessageToChannel(botChannel, nextBotMessage);
    counter.value = parseInt(userMessage.match(' [0-9]*'));

    status.value = statusNext;
    return;  
    } 
}

0 个答案:

没有答案