Javascript 如何用一个命令处理几个问题?
我让hubot放松只是为了好玩 我想实现的是让hubot同时得到几个问题。例如,如下所示: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源代码 呼叫部分:
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
实现
有没有其他方法来实现这一点?如果没有,我应该将此函数分成许多部分,如添加作业
,添加工作场所
等等