How to Build a Serverless Chatbot for $0?

Preview:

Citation preview

HOW TO BUILD A SERVERLESS CHATBOT

FOR $0

I’M SLOBODAN STOJANOVIC

CTO OF CLOUD HORIZON JS BELGRADE MEETUP ORGANIZER

GITHUB.COM/STOJANOVIC TWITTER.COM/SLOBODAN_

CLOUD HORIZON

WE HELP BUSINESSES BUILD INNOVATIVE WEB AND MOBILE SOLUTIONS

CHATTERBOT / CHAT BOT a type of conversational agent, a computer

program designed to simulate an intelligent conversation with one or more human users

via auditory or textual methods.

A BIT OF A HISTORY

• Turing Test (1950) • Eliza (1966) • Parry (1972) • A.L.I.C.E. (1995) • Jabberwacky (2005) • Slack Bot (2014) • Telegram and FB Bots (2015) • Many others (2016)

WHEN PARRY MET ELIZA

CHATBOT PLATFORMS

HOW CHATBOTS WORK

MOST OF THEM ARE USING WEBHOOKS

Hello

{ sender: { id: 12345 }, recipient: { id: 54321 }, timestamp: 1483413621558, message: { app_id: 999999, text: 'Hello' }}

{ recipient: { id: '12345' }, message: { text: 'Hi there' }}

Hi there

MOST OF THEM? WHAT ABOUT THE DIFFERENT ONES?

• Slack Bot users • Amazon Alexa • iMessage and Siri

WHAT DO YOU NEED TO KNOW TO BUILD A CHATBOT

ARTIFICIAL INTELLIGENCE

NATURAL LANGUAGE PROCESSING

<PROGRAMMING/>

WHAT DO YOU NEED TO KNOW TO SETUP A CHATBOT

• Server • SSL • Setup API / Webhooks • Register app / bot • Setup tokens, webhook url, etc. • Write the logic • …

IS THERE A BETTER WAY?

YES, OF COURSE!

• Visual chatbot builders (Chatfuel) • Bot frameworks (Microsoft Bot Framework) • Amazon Lex • Many other options

BUILDING CHATBOTS IS NOT FUN, MOST OF THE TIME

AT LEAST, NOT AS MUCH AS IT SHOULD BE

WE DECIDED TO FIX THAT

AT LEAST, FOR US

MEET CLAUDIA BOT BUILDER

Claudia Bot Builder is an extension library for Claudia.js that helps you create bots

for 10 platforms.

The key idea behind the project is to remove all the boilerplate code and

common infrastructure tasks, so you can focus on writing the really important part

of the bot – your business workflows.

OK, LET ME SHOW YOU

var botBuilder = require('claudia-bot-builder')

module.exports = botBuilder(function(message) { return 'Hi there! You sent “' + message.text + '“'})

const botBuilder = require('claudia-bot-builder')

module.exports = botBuilder(message => `Hi there! You sent “${message.text}”`)

• AMAZON WEB SERVICES ACCOUNT • Node.js (version 4.3.2 is preferred) • Install Claudia and Claudia Bot Builder from NPM

PREREQUISITES

claudia create --region eu-central-1 --api-module bot

SIMPLY RUN ONE COMMAND TO DEPLOY THE BOT

TO SETUP DIFFERENT PLATFORMS

ADD ANOTHER FLAG

claudia create \ --region eu-central-1 \ --api-module bot \ --configure-fb-bot

ALL SUPPORTED PLATFORMS

• configure-fb-bot • configure-slack-slash-command • configure-slack-slash-app • configure-viber-bot • configure-telegram-bot • configure-skype-bot • configure-alexa-skill • configure-twilio-sms-bot • configure-kik-bot • configure-groupme-bot

LET’S SEE IT

HOW IT WORKS

zzz…

{ sender: { id: 12345 }, recipient: { id: 54321 }, timestamp: 1483413621558, message: { app_id: 999999, text: 'Hello' }}

{ recipient: { id: '12345' }, message: { text: 'Hi there' }}

{ sender: 12345, platform: ’facebook’, text: ‘Hello’, postback: false, originalRequest: {…}}

HelloHi there

PRICE

$0

AWS LAMBDA PRICING

• $0.20 per 1 million requests • $0.00001667 for every GB-second used • First million requests each month are free • First 400,000 GB-seconds are free

AWS LAMBDA IS STATELESS.

HOW DO WE SAVE THE STATE?

USE DYNAMO DB

IS THERE AN EASIER WAY TO BUILD COMPLEX

MESSAGES?

YES!

const botBuilder = require('claudia-bot-builder');const fbTemplate = botBuilder.fbTemplate;

module.exports = botBuilder(message => { if (message.type === 'facebook') { const newMessage = new fbTemplate.Text('What\'s your favorite House in Game Of Thrones');

return newMessage .addQuickReply('Stark', 'STARK') .addQuickReply('Lannister', 'LANNISTER') .addQuickReply('Targaryen', 'TARGARYEN') .addQuickReply('None of the above', 'OTHER') .get(); }});

CAN WE ADD NLP FOR $0 TOO?

YES OF COURSE, THERE’S A FEW OPTIONS:

• API.ai • Wit.ai • IBM Watson* • Luis.ai

EXAMPLES?

CLAUDIA.JS EXAMPLE PROJECTS:

GITHUB.COM/CLAUDIAJS/EXAMPLE-PROJECTS

SAMPLE BOTS:

SPACE EXPLORER FB BOT:

M.ME/SPACE.EXPLORER.BOTGITHUB.COM/STOJANOVIC/SPACE-EXPLORER-BOT

LAPTOP FRIENDLY VIBER BOT:

VIBER.COM/LAPTOPFRIENDLY GITHUB.COM/STOJANOVIC/LAPTOP-FRIENDLY-BOT

HOLYJS CONFERENCE BOT:

TELEGRAM.ME/HOLYJS_BOTGITHUB.COM/STOJANOVIC/HOLYJS-BOT

VACATION TRACKER FOR SLACK:

VACATIONTRACKERBOT.COM

VACATIONTRACKERBOT.COM

MORE INFO

CLAUDIAJS.COM

GITHUB.COM/CLAUDIAJS/CLAUDIA-BOT-BUILDER

WHAT’S NEXT?

QUESTIONS?

@SLOBODAN_

SLIDES: bit.ly/2kjaegq

Recommended