30
1 Serverless Chatbots with PubNub and Conversation

Building with Watson - Serverless Chatbots with PubNub and Conversation

Embed Size (px)

Citation preview

Page 1: Building with Watson - Serverless Chatbots with PubNub and Conversation

1

Serverless Chatbotswith PubNub and Conversation

Page 2: Building with Watson - Serverless Chatbots with PubNub and Conversation

2

Housekeeping ItemsWebinar slides, live recording and Q&A will be

emailedAsk questions at any time during the presentation Use chat window on the webinar panel We're on Twitter: @IBMWatson

#BuildingWithWatson

Page 3: Building with Watson - Serverless Chatbots with PubNub and Conversation

Watson / Presentation Title / Date3

Our Expert

Josh MarinacciHead of Developer [email protected]

Page 4: Building with Watson - Serverless Chatbots with PubNub and Conversation

Serverless Chatbots

What is Serverless?

Page 5: Building with Watson - Serverless Chatbots with PubNub and Conversation

5

What does Serverless MeanProgram functions, not apps or servers.CDN for computation, in the network, near the

user.Acts as a single computerTalks to 3rd party micro-services Infinitely Scalable

Page 6: Building with Watson - Serverless Chatbots with PubNub and Conversation

6

Introducing PubNub BLOCKSPromise based modern JavaScriptRuns in the network, nearest to userVery low latencyVery high security Infinitely Scalable

Page 7: Building with Watson - Serverless Chatbots with PubNub and Conversation

7

Chatbot RequirementsRealtime InfrastructureSome level of Artificial IntelligenceDomain specific knowledge

But remember...Requirements, not focus

So... Don’t build your own Realtime InfrastructureDon’t build your own Artificial Intelligence

Page 8: Building with Watson - Serverless Chatbots with PubNub and Conversation

Heart Bot

Demo

Page 9: Building with Watson - Serverless Chatbots with PubNub and Conversation

9

Heart Bot

Page 10: Building with Watson - Serverless Chatbots with PubNub and Conversation

10

Aggregation queryexport default (request) => { var txt = request.message.text; txt = txt.replace(/poop/g,"\uD83D\uDCA9"); txt = txt.replace(/crap/g,"\uD83D\uDCA9"); txt = txt.replace(/love/g,"\uD83D\uDE0D"); txt = txt.replace(/heart/g,"\uD83D\uDC9C"); txt = txt.replace(/sad/g,"\uD83D\uDE1E"); txt = txt.replace(/happy/g,"\uD83D\uDE04");

request.message.text = "Your message isn't hearty enough!" +" There I fixed it: <br/>" + txt; return request.ok(); // Return a promise when you're done}

Page 11: Building with Watson - Serverless Chatbots with PubNub and Conversation

Image Bot

Demo

Page 12: Building with Watson - Serverless Chatbots with PubNub and Conversation

12

Image Bot

Page 13: Building with Watson - Serverless Chatbots with PubNub and Conversation

Parse Textvar words = text.split(" ") .map((w)=>w.toLowerCase()) .filter((w)=>{ if(w === 'the')return false; if(w === 'to') return false;… return true; });if(!words.includes("please")) return false;var n = words.findIndex((w) => w === 'please');var verb = words[n+1];if(verb === 'upload') return upload(words);if(verb === 'display') return display(rest);if(verb === 'show') return show(rest);if(verb === 'resize') return resize(rest);...

Page 14: Building with Watson - Serverless Chatbots with PubNub and Conversation

Process Commandreturn db.get('context').then((context) => { if(!context) context = {}; var command = request.message; if(command.action === 'resize')

context.width = command.size; if(command.action === 'crop') { context.crop = true; context.shape = 'square'; context.gravity = command.gravity; } …

Page 15: Building with Watson - Serverless Chatbots with PubNub and Conversation

Generate Cloudinary URL let apiUrl = 'http://res.cloudinary.com/' + cloudName + '/' + resource + '/' + operation + '/'; apiUrl += filename + '.' + context.format;

request.message.cloudinaryURL = apiUrl;

db.set('context',context); return request.ok();});

Page 16: Building with Watson - Serverless Chatbots with PubNub and Conversation

Mr RockbotDemo

Page 17: Building with Watson - Serverless Chatbots with PubNub and Conversation

17

Mr Rockbot

Page 18: Building with Watson - Serverless Chatbots with PubNub and Conversation

18

Watson Alchemy APIs

Page 19: Building with Watson - Serverless Chatbots with PubNub and Conversation

Check Languageconst query_params = { outputMode:'json', apikey:'494a8df6f920d85b1de4a8172c21dbc264d6446f', extract:'keywords,relations,language', maxRetrieve: 1, text:request.message.text};var url = "http://gateway-a.watsonplatform.net/calls/text/TextGetCombinedData?" +query.stringify(query_params);

return xhr.fetch(url).then((x)=>{ var ret = JSON.parse(x.body); if(ret.language != 'english') { return translateMessage(request.message, ret.language); } return cookMessage(ret);});

Page 20: Building with Watson - Serverless Chatbots with PubNub and Conversation

20

Conversation Service

Page 21: Building with Watson - Serverless Chatbots with PubNub and Conversation

Create Intents

Page 22: Building with Watson - Serverless Chatbots with PubNub and Conversation

Create Entities

Page 23: Building with Watson - Serverless Chatbots with PubNub and Conversation

Create Dialogs

Page 24: Building with Watson - Serverless Chatbots with PubNub and Conversation

Process Dialogvar url = creds.url+'/v1/workspaces/'+creds.workspaceID+'/message?version=2016-09-20';

var payload = { input: { text: request.message.text } }

return kvstore.get("context").then((ctx) => { if(ctx) payload.context = ctx;

const http_options = { method:'POST', body: JSON.stringify(payload) }

return xhr.fetch(url, http_options).then((x)=>{ var body = JSON.parse(x.body); return kvstore.set("context",body.context).then(()=>{ request.message.text = body.output.text[0]; request.message.watson = body; return request.ok(); }); });});

Page 25: Building with Watson - Serverless Chatbots with PubNub and Conversation

25

Mr Rockbot

Page 26: Building with Watson - Serverless Chatbots with PubNub and Conversation

26

Lessons LearnedUse a Serverless NetworkUse stateless AI micro-servicesStore context in the network, near the users

Page 27: Building with Watson - Serverless Chatbots with PubNub and Conversation

27

Q&A

Page 29: Building with Watson - Serverless Chatbots with PubNub and Conversation

29

What’s next? Look out for a follow up email with a copy of these slides, a recording of

the webinar, Q&A recap, and additional resources

The series will continue bi-weekly on Wednesdays @ 1pm ET / 10am PT

Advanced Audio Transcription with Watson Speech-to-Text - March 8Easily Deploy your Chat Bot to Multiple Channels with Stamplay -

March 22

Page 30: Building with Watson - Serverless Chatbots with PubNub and Conversation

30

Thank you for attending!

Contact usPhone: 1-877-253-0308

Email: [email protected]: Watson Developer Cloud