Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何用一个命令处理几个问题?_Javascript_Prompt_Hubot_Slack Api - Fatal编程技术网

Javascript 如何用一个命令处理几个问题?

Javascript 如何用一个命令处理几个问题?,javascript,prompt,hubot,slack-api,Javascript,Prompt,Hubot,Slack Api,我让hubot放松只是为了好玩 我想实现的是让hubot同时得到几个问题。例如,如下所示: user : @hubot: add job hubot : what is your job ? user : jobless hubot : where is your workplace ? user : home hubot : your job has registered. 如您所见,用户将使用命令addjob仅触发事件一次。 下面是我处理它的javascript源代码 呼叫部分:

我让hubot放松只是为了好玩

我想实现的是让hubot同时得到几个问题。例如,如下所示:

user : @hubot: add job 
hubot : what is your job ? 
user : jobless 
hubot : where is your workplace ? 
user : home 
hubot : your job has registered.
如您所见,用户将使用命令
addjob
仅触发事件一次。 下面是我处理它的javascript源代码

呼叫部分:

robot.respond(/register me/igm, function(msg){
    //var promptConsole = new Prompt(msg);
    var questions = [
        {'question' : 'What is your name ?', 'dataname' : 'name'}
        , {'question' : 'What is your job ?', 'dataname' : 'job'}
    ];
    var promptConsole = new Prompt(msg, questions);
    promptConsole.init().startPrompt(robot);
});
和提示对象:

var Prompt = function (msg, questions) {

    console.log(msg);
    this.msg = msg;
    this.user = msg.message.user;
    this.room = msg.message.room;
    this.results;
    this.questions = questions;

    //console.log(user +' is in room [ ' + room + ' ] ');

    this.init = function () {
        this.results = [];
        for(var i = 0; i < questions.length; i ++) {
            var singleQuestion = questions[i];
            var result = {'key': '', 'question' : '', 'value' : ''};
            result.key = singleQuestion.dataname;
            result.question = singleQuestion.question;
            this.results.push(result);
        }
        return this;
    }

    this.startPrompt = function () {
        for(var i = 0; i < this.results.length; i ++) {
            console.log(this.results[i]);
            this.msg.send(this.results[i].question);
        }
    }
}
var Prompt=函数(消息,问题){
控制台日志(msg);
this.msg=msg;
this.user=msg.message.user;
this.room=msg.message.room;
这就是结果;
这个。问题=问题;
//console.log(user+'在房间['+room+']'中);
this.init=函数(){
这个结果=[];
对于(var i=0;i
但是,由于用户输入只发生一次,因此此功能不能用
robot.hear
robot.respond
实现

有没有其他方法来实现这一点?如果没有,我应该将此函数分成许多部分,如
添加作业
添加工作场所
等等