At the end of this class, you will be able to:
wilson-espina/jsd-9-resources
repo to your computer:cd
to the Documents/JSD/jsd-9-resources
directorygit pull origin master
and press return
Documents/JSD/jsd-9-resources/07-slackbot-lab
const course = '{"name":"JSD","weeks":
10,"location":"Remote","instructor":
"Wilson Espina","students":["Mr
Motivator","Cathy Burke","Carl Cox",
"Steven King","Susie Dent"],"dates":
{"start":"2020-05-11","end":"2020-07-
20"}}'
Open up: 1-cat-facts-json
yo
, which takes care of things like:Key Objective
Location
Timing
20 mins |
|
module.exports = function(robot) {
// command 1
robot.verb(parameter1, function(res) {
return res.command();
});
// command 2
robot.verb(parameter1, function(res) {
return res.command();
});
...
}
bot.hear(/Hello!/, function(res) {
return res.send("Hi there!");
});
tim: Hello!
hubot: Hi there!
bot.respond(/What's your favourite food?/, function(res) {
return res.send("I'm a robot--I don't eat food!");
});
tim: @hubot What's your favourite food?
hubot: I'm a robot--I don't eat food!
jon: What's your favourite food?
... [no response because Jon didn't tag Hubot in his message]
.send
method allows your Hubot to send a message to the channel..reply
method allows it to respond directly to a user with an @ reply.(.*)
wildcards allow us to accept user input in your script.
bot.respond(/Hi Hubot! My name is (.*)/i, function(msg) {
let name;
name = msg.match[1];
if (name == "Hubot"){
return msg.send("You're not Hubot--I'm Hubot!");
} else {
return msg.reply("Nice to meet you, " + name + "!");
}
});
module.exports = function(robot) {
robot.hear(/Hello!/, function(res) {
return res.send("Hi there!");
})
}
module.exports = function(bot) {
bot.respond(/Hello!/, function(res) {
return res.send("Hi there!");
})
}
bro-bot> Hello!
bro-bot>
bro-bot> @bro-bot Hello!
bro-bot> Hi there!
module.exports = function(bot) {
bot.hear(/Hello!/, function(res) {
return res.send("Hi there!");
});
};
module.exports = function(bot) {
bot.hear(/Yo/, function(res) {
return res.send("Heya");
});
};
bro-bot> Hello!
bro-bot>
bro-bot> Yo
bro-bot> Heya
module.exports = function(bot) {
bot.hear(/Hello!/, function(res) {
return res.send("Hi there!");
});
bot.hear(/Yo/, function(res) {
return res.send("Heya");
});
};
bro-bot> Hello!
bro-bot> Hi there!
bro-bot> Yo
bro-bot> Heya
Bot is asleep if the status indicator is not green.
$ heroku ps:restart
Key Objective
Location
Timing
Until 20:45 |
|
(Lesson #07)