[IBM Watson Online Meetup - April 17, 2019]
In this interactive workshop, Tomomi Imura from Slack and David Nugent from IBM Developer SF City Team will walk you through building a bot using Slack's API and Block Kit, and making it smarter using IBM Watson.
Tomomi will walk you through how to build a Slack bot with Slack API using Node SDK, and improve the bot with Slack’s new Block Kit Builder. She will also cover how to make the bot smarter using IBM Watson.
This session uses Node.js, however, you should be able to follow if you have a general understanding in any programming language. All you need is a Chrome browser to try out the sample code.
44. User post a message,
“Hi @help_bot”
Sends payload to
request URL
chat.postMessage
Post a
message
Hi here’s some info!
Hi @help_bot
app_mention
event is triggered
62. app_mention
// Greeting any user mentions your bot, @greet_bot
slackEvents.on('app_mention', (message) => {
// When the message is a plain messages and contain 'hi' (case insensitive)
if (/hi/i.test(message.text))) {
// Respond to the message back in the same channel
slack.chat.postMessage(
{ channel: message.channel, text: `Hello <@${message.user}>! :wave:` }
)
}
});
66. const messageBlocks = [
{
"type": "section",
"text": {
"text": "Hello, welcome to the *Workspace X*nHere's a list of info you are probably looking for:"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<https://example.com|*Cafeteria*> n Building 1nSouth-East cornernOpen: 8am - 5pm"
},
"accessory": {
"type": "image",
"image_url": "https://upload.wikimedia.org/wikipedia/commons/3/3b/BHS-Cafeteria.jpg",
"alt_text": "cafeteria"
}
},
// ...
]
n = new line
71. Sends payload to
request URL
chat.postMessage
Post message
Hi here’s some info!
Show me office
directory!
Extract user-sent
message & pass
Process & return
User post a message,
“Hi @help_bot”
app_mention
event is triggered