javascript - hubot-slack with js - how to handle several questions with only one command? -
i making hubot-slack fun.
the thing want implement let hubot several questions @ once. instance, below:
user : @hubot: add job hubot : job ? user : jobless hubot : workplace ? user : home hubot : job has registered.
as can see, user trigger event once command add job
. following javascript source handle it.
calling part :
robot.respond(/register me/igm, function(msg){ //var promptconsole = new prompt(msg); var questions = [ {'question' : 'what name ?', 'dataname' : 'name'} , {'question' : 'what job ?', 'dataname' : 'job'} ]; var promptconsole = new prompt(msg, questions); promptconsole.init().startprompt(robot); });
and prompt object :
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 +' in room [ ' + room + ' ] '); this.init = function () { this.results = []; for(var = 0; < questions.length; ++) { 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 = 0; < this.results.length; ++) { console.log(this.results[i]); this.msg.send(this.results[i].question); } } }
however, function can not implemented robot.hear
or robot.respond
, since user input happens once.
is there other way implement this? if not, should separate function many part add job
, add workplace
, on.
Comments
Post a Comment