Let’s Get Chatty!
Building Serverless Slack Chatbot on IBM Cloud Functions
Serverless Dev Summit | July 26, 2019
@girlie_mac
Hello world!
Tomomi Imura
( @girlie_mac)
2
What Are Bots?
A bot is a software application that runs automated
tasks (scripts).
Typically, bots perform tasks that are both simple
and structurally repetitive, at a much higher rate
than would be possible for a human alone.
https://en.wikipedia.org/wiki/Internet_bot
@girlie_mac
Also, it is a user experience that can expose
services to users via conversational engagement
and rich interactions.
What Are Bots?
@girlie_mac
"Bots are like new applications
that you can converse with."
-- Satya Nadella, Microsoft (2016)
Future of computing revolves
around three principal factors:
● Humans
● Digital assistants
● Bots
Conversational User Interactions
Conversational User Interactions
Voice Assistance
Alexa, how is the
weather?
Hey Siri
@girlie_mac
Conversational User Interactions
Google Assistant (Voice & Text)
Hi, how can I help?
@girlie_mac
Conversational User Interactions
Bots on Chat Apps (Text)
!
@girlie_mac
Conversational Bots on Facebook Messanger
KLM Royal Dutch Airlines
BlueBot (BB)
On Facebook Messenger
Conversational Bots on Multiple Platforms
UPS Chatbot
On
● Facebook Messenger
● Skype
● Google Assistant
● Amazon Alexa
Conversational Bots on Slack
Geekbot
@girlie_mac
Conversational Bots on Slack
Taco Bot
https://www.tacobell.com/feed/tacobot@girlie_mac
Building A Conversational App on Slack
Example: A simple bot that responds to “Hi”
Hi
Hello
@girlie_mac
with Slack API
● Events API to listen to an event (message.im)
when a user sends a direct message to your bot
● When an event is triggered, receive a payload
to get a message text
● Use Web API method, chat.postMessage to
post a message on Slack
@girlie_mac
User DM a message
Sends payload to
request URL
USER Bot SLACK
chat.postMessage
Reply to
the user Hello
Hi
message.im
event is triggered
Process the
payload. Extract
the user’s
message & see if
the message
contains a word,
“Hi”
Chatbot with RegEx = Not so conversational
if(/hi/i.test(event.text)) {
reply(‘Hello’);
}
Hi
Hello
@girlie_mac
Make it Smarter with NLP
if(/hi/i.test(event.text)) {
reply(...);
}
Hi
I need help
Guide me
Show me the
floor map
@girlie_mac
What is Natural Language Processing?
Process and analyze natural language data to
make the interactions between computers &
human, artificial & natural languages possible
Conversational Bots & NLP
@girlie_mac
Using Watson Assistant
Watson Assistant makes it smarter!
Sends payload to
request URL
USER BOT SLACK
chat.postMessage
Reply to the
user
Hi here’s some info!
Show me office
directory!
WATSON
Extract user-sent
message & pass
Process & return
User DM a message
message.im
event is triggered
bot.js (Receive Slack events & Post message)
exports.handler = async function handler(params) {
const {challenge, event} = params;
await reply(event.channel, event.text);
return {statusCode: 200};
}
// Get a reply from Watson Assistant
const reply = async(channel, text) => {
const params = {
assistant_id: WATSON_ASSISTANT_ID,
input: { text: text }
};
const result = await assistant.message(params);
sendToSlack(channel, result.output.generic[0].text);
When DM is sent in Slack
Pass the message text from
the user to the function that
handles:
1. Get a reply message via
Watson API
2. Post it on Slack
Watson returns the response
Post the response to Slack
Going serverless
Why do you wanna go serverless?
1
Cost-effective
Lowerinfrastructure&
operationalcost
2
Scalable
From
prototypetoproduction
3
Sim
plefunctions
Sim
plifiedprogram
m
ingm
odel
@girlie_mac
IBM Cloud Functions
HTTP
User
Cloud
(IBM Cloud Functions)
Chatbot
(Slack App)
HTTP
API Gateway
IBM Watson
Assistant
@girlie_mac
IBM Cloud Functions - Create an Action
@girlie_mac
.
├── .env
├── index.js
├── bot.js
├── package.json
├── readme.md
└── node_modules
├── some_module
...
My Files
const botEndpoint = require('./bot');
module.exports = {
main: botEndpoint.handler
};
index.js
@girlie_mac
IBM Cloud CLI
tomomi: ~/dev/slack/ibm/slack-bot-watson (zsh)
> zip -r chatbot.zip *
> ibmcloud fn action create slack-chatbot chatbot.zip
--kind nodejs:10
@girlie_mac
Receiving HTTP Events
1
@girlie_mac
Expose API Endpoint to Create a Public URL
1
2
Click Create
Managed API
to open the
pop-up
3
Define the API
endpoint. Select
your Action.
4
@girlie_mac
Send Slack Events the URL
1
2
3
4
Go to Slack
Config page
Use the public
URL
@girlie_mac
Result
@girlie_mac
Source Code
Source code on GitHub:
https://github.com/girliemac/serverless-slack-watson
not yet,sorry!
@girlie_mac
Resources
★ Slack API Docs: https://api.slack.com
★ Slack events types: https://api.slack.com/events
★ Watson Assistant: https://cloud.ibm.com/docs/services/assistant
★ Watson Node SDK:
https://www.npmjs.com/package/watson-developer-cloud
★ IBM Cloud Functions: https://www.ibm.com/cloud/functions
★ Cloud Functions CLI:
https://cloud.ibm.com/docs/cloud-functions-cli-plugin
@girlie_mac
Slack x IBM Watson Webinar (Recorded)
https://www.crowdcast.io/e/online-meetup-build-a
@girlie_mac
You’re invited to Spec, a developer conference by Slack.
Learn more at slack.com/spec
Get 30% off registration with code -S19_SPC30
Thank you!
Tomomi Imura (@girlie_mac)

[2019 Serverless Summit] Building Serverless Slack Chatbot on IBM Cloud Functions

  • 1.
    Let’s Get Chatty! BuildingServerless Slack Chatbot on IBM Cloud Functions Serverless Dev Summit | July 26, 2019
  • 2.
  • 3.
    What Are Bots? Abot is a software application that runs automated tasks (scripts). Typically, bots perform tasks that are both simple and structurally repetitive, at a much higher rate than would be possible for a human alone. https://en.wikipedia.org/wiki/Internet_bot @girlie_mac
  • 4.
    Also, it isa user experience that can expose services to users via conversational engagement and rich interactions. What Are Bots? @girlie_mac
  • 5.
    "Bots are likenew applications that you can converse with." -- Satya Nadella, Microsoft (2016)
  • 6.
    Future of computingrevolves around three principal factors: ● Humans ● Digital assistants ● Bots
  • 7.
  • 8.
    Conversational User Interactions VoiceAssistance Alexa, how is the weather? Hey Siri @girlie_mac
  • 9.
    Conversational User Interactions GoogleAssistant (Voice & Text) Hi, how can I help? @girlie_mac
  • 10.
    Conversational User Interactions Botson Chat Apps (Text) ! @girlie_mac
  • 11.
    Conversational Bots onFacebook Messanger KLM Royal Dutch Airlines BlueBot (BB) On Facebook Messenger
  • 12.
    Conversational Bots onMultiple Platforms UPS Chatbot On ● Facebook Messenger ● Skype ● Google Assistant ● Amazon Alexa
  • 13.
    Conversational Bots onSlack Geekbot @girlie_mac
  • 14.
    Conversational Bots onSlack Taco Bot https://www.tacobell.com/feed/tacobot@girlie_mac
  • 15.
  • 16.
    Example: A simplebot that responds to “Hi” Hi Hello @girlie_mac
  • 17.
    with Slack API ●Events API to listen to an event (message.im) when a user sends a direct message to your bot ● When an event is triggered, receive a payload to get a message text ● Use Web API method, chat.postMessage to post a message on Slack @girlie_mac
  • 18.
    User DM amessage Sends payload to request URL USER Bot SLACK chat.postMessage Reply to the user Hello Hi message.im event is triggered Process the payload. Extract the user’s message & see if the message contains a word, “Hi”
  • 19.
    Chatbot with RegEx= Not so conversational if(/hi/i.test(event.text)) { reply(‘Hello’); } Hi Hello @girlie_mac
  • 20.
    Make it Smarterwith NLP if(/hi/i.test(event.text)) { reply(...); } Hi I need help Guide me Show me the floor map @girlie_mac
  • 21.
    What is NaturalLanguage Processing? Process and analyze natural language data to make the interactions between computers & human, artificial & natural languages possible Conversational Bots & NLP @girlie_mac
  • 22.
  • 23.
  • 24.
    Sends payload to requestURL USER BOT SLACK chat.postMessage Reply to the user Hi here’s some info! Show me office directory! WATSON Extract user-sent message & pass Process & return User DM a message message.im event is triggered
  • 25.
    bot.js (Receive Slackevents & Post message) exports.handler = async function handler(params) { const {challenge, event} = params; await reply(event.channel, event.text); return {statusCode: 200}; } // Get a reply from Watson Assistant const reply = async(channel, text) => { const params = { assistant_id: WATSON_ASSISTANT_ID, input: { text: text } }; const result = await assistant.message(params); sendToSlack(channel, result.output.generic[0].text); When DM is sent in Slack Pass the message text from the user to the function that handles: 1. Get a reply message via Watson API 2. Post it on Slack Watson returns the response Post the response to Slack
  • 26.
  • 27.
    Why do youwanna go serverless? 1 Cost-effective Lowerinfrastructure& operationalcost 2 Scalable From prototypetoproduction 3 Sim plefunctions Sim plifiedprogram m ingm odel @girlie_mac
  • 28.
    IBM Cloud Functions HTTP User Cloud (IBMCloud Functions) Chatbot (Slack App) HTTP API Gateway IBM Watson Assistant @girlie_mac
  • 29.
    IBM Cloud Functions- Create an Action @girlie_mac
  • 30.
    . ├── .env ├── index.js ├──bot.js ├── package.json ├── readme.md └── node_modules ├── some_module ... My Files const botEndpoint = require('./bot'); module.exports = { main: botEndpoint.handler }; index.js @girlie_mac
  • 31.
    IBM Cloud CLI tomomi:~/dev/slack/ibm/slack-bot-watson (zsh) > zip -r chatbot.zip * > ibmcloud fn action create slack-chatbot chatbot.zip --kind nodejs:10 @girlie_mac
  • 32.
  • 33.
    Expose API Endpointto Create a Public URL 1 2 Click Create Managed API to open the pop-up 3 Define the API endpoint. Select your Action. 4 @girlie_mac
  • 34.
    Send Slack Eventsthe URL 1 2 3 4 Go to Slack Config page Use the public URL @girlie_mac
  • 35.
  • 36.
    Source Code Source codeon GitHub: https://github.com/girliemac/serverless-slack-watson not yet,sorry! @girlie_mac
  • 37.
    Resources ★ Slack APIDocs: https://api.slack.com ★ Slack events types: https://api.slack.com/events ★ Watson Assistant: https://cloud.ibm.com/docs/services/assistant ★ Watson Node SDK: https://www.npmjs.com/package/watson-developer-cloud ★ IBM Cloud Functions: https://www.ibm.com/cloud/functions ★ Cloud Functions CLI: https://cloud.ibm.com/docs/cloud-functions-cli-plugin @girlie_mac
  • 38.
    Slack x IBMWatson Webinar (Recorded) https://www.crowdcast.io/e/online-meetup-build-a @girlie_mac
  • 39.
    You’re invited toSpec, a developer conference by Slack. Learn more at slack.com/spec Get 30% off registration with code -S19_SPC30
  • 40.