Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Dr. Strangelove or: How I Learned to Stop Worry...
Search
Slobodan Stojanović
December 11, 2016
Technology
1
250
Dr. Strangelove or: How I Learned to Stop Worrying and Love the Serverless Chatbots - HolyJS 2016
Presentation from HolyJS 2016 conference in Moscow
Slobodan Stojanović
December 11, 2016
Tweet
Share
More Decks by Slobodan Stojanović
See All by Slobodan Stojanović
Prompt Engineering for Developers @ AWS Community Day Adria 2024
slobodan
0
180
From 1 to 250 Lambda Functions in Production: Evolving a Startup Serverless Architecture @ Serverless Days Milan
slobodan
0
110
Building Production-Ready Apps with AI
slobodan
0
210
Advanced GraphQL Architectures: Serverless Event Sourcing and CQRS @ ReactSummit
slobodan
0
190
CofounderGPT - Can an AI be a better co-founder than a human?
slobodan
0
140
From 1 to 201 Lambda functions in production: Evolving a serverless startup architecture
slobodan
0
280
Evolving a serverless startup architecture - ArmadaJS 2022
slobodan
2
460
Serverless Office Hours | Serverless for Startups
slobodan
0
210
From 1 to 101 Lambda Functions in Production: Evolving a Serverless Architecture - Node Congress 2021
slobodan
1
320
Other Decks in Technology
See All in Technology
エンジニア人生の拡張性を高める 「探索型キャリア設計」の提案
tenshoku_draft
1
130
IBC 2024 動画技術関連レポート / IBC 2024 Report
cyberagentdevelopers
PRO
0
110
Application Development WG Intro at AppDeveloperCon
salaboy
0
190
ノーコードデータ分析ツールで体験する時系列データ分析超入門
negi111111
0
410
マルチプロダクトな開発組織で 「開発生産性」に向き合うために試みたこと / Improving Multi-Product Dev Productivity
sugamasao
1
310
オープンソースAIとは何か? --「オープンソースAIの定義 v1.0」詳細解説
shujisado
9
960
信頼性に挑む中で拡張できる・得られる1人のスキルセットとは?
ken5scal
2
530
SSMRunbook作成の勘所_20241120
koichiotomo
2
140
Introduction to Works of ML Engineer in LY Corporation
lycorp_recruit_jp
0
120
Amazon Personalizeのレコメンドシステム構築、実際何するの?〜大体10分で具体的なイメージをつかむ〜
kniino
1
100
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
3.2k
開発生産性を上げながらビジネスも30倍成長させてきたチームの姿
kamina_zzz
2
1.7k
Featured
See All Featured
Site-Speed That Sticks
csswizardry
0
25
Building an army of robots
kneath
302
43k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Producing Creativity
orderedlist
PRO
341
39k
What's new in Ruby 2.0
geeforr
343
31k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Side Projects
sachag
452
42k
Transcript
DR.STRANGELOVE OR: HOW I LEARNED TO STOP WORRYING AND LOVE
THE SERVERLESS CHATBOTS
#holyjs @slobodan_ I am Slobodan Stojanović CTO of Cloud Horizon
and JS Belgrade Meetup organizer github.com/stojanovic twitter.com/slobodan_
#holyjs @slobodan_ Walt Disney American entrepreneur, cartoonist, animator…
#holyjs @slobodan_ CHATBOTS
#holyjs @slobodan_ IDEA IS NOT NEW
#holyjs @slobodan_ • 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)
#holyjs @slobodan_ SERVERLESS
#holyjs @slobodan_ FUNCTION AS A SERVICE
#holyjs @slobodan_ • AWS Lambda (2014) • Google Cloud Functions
(2016) • IBM OpenWhisk (2016) • Microsoft Azure Functions (2016)
#holyjs @slobodan_ SERVERLESS + CHATBOTS
#holyjs @slobodan_ Whitney Houston American singer
#holyjs @slobodan_
#holyjs @slobodan_
#holyjs @slobodan_
#holyjs @slobodan_
#holyjs @slobodan_
#holyjs @slobodan_ MEET CLAUDIA BOT BUILDER
#holyjs @slobodan_ var botBuilder = require('claudia-bot-builder') module.exports = botBuilder(function (message)
{ return 'Thanks for sending ' + message.text })
#holyjs @slobodan_ OR WITH ES6
#holyjs @slobodan_ const botBuilder = require('claudia-bot-builder') module.exports = botBuilder(message =>
`Thanks for sending: ${message.text}` )
#holyjs @slobodan_
#holyjs @slobodan_
#holyjs @slobodan_ LET’S BUILD A TELEGRAM BOT FOR #HOLYJS
#holyjs @slobodan_ Edgar Allan Poe American writer
#holyjs @slobodan_ WITH $0.00 BUDGET
#holyjs @slobodan_ Albert Einstein German-born theoretical physicist
#holyjs @slobodan_ PART 1. SETUP AWS
#holyjs @slobodan_ Nikola Tesla Serbian American inventor
#holyjs @slobodan_ THE ONLY PREREQUISITES FOR CLAUDIA BOT BUILDER ARE
AN AWS ACCOUNT AND NODE.JS
#holyjs @slobodan_ WHAT DO WE NEED?
#holyjs @slobodan_ (NEW) AWS USER WITH FOLLOWING PERMISSIONS: • AWS
Lambda full access • IAM full access (optional) • API Gateway Administrator • API Gateway push to CloudWatch • Cloud Watch full access (optional)
#holyjs @slobodan_ LET’S SEE
#holyjs @slobodan_
#holyjs @slobodan_ PART 2. BOTFATHER
#holyjs @slobodan_ Sigmund Freud Austrian neurologist
#holyjs @slobodan_ THERE’S A TELEGRAM BOT THAT HELPS YOU TO
CREATE TELEGRAM BOTS!
#holyjs @slobodan_
#holyjs @slobodan_
#holyjs @slobodan_ PART 3. SIMPLE BOT
#holyjs @slobodan_ Isaac Newton English physicist and mathematician
#holyjs @slobodan_ BEFORE WE BEGIN WE NEED TO INSTALL CLAUDIA
https://claudiajs.com
#holyjs @slobodan_ $ npm install claudia -g
#holyjs @slobodan_ const botBuilder = require('claudia-bot-builder') module.exports = botBuilder(message =>
{ return 'Hello from HolyJS bot! You sent: ' + message.text }, { platforms: ['telegram'] }) bot.js file:
#holyjs @slobodan_ $ npm init; $ npm i claudia-bot-builder -S
#holyjs @slobodan_ $ claudia create\ --region eu-central-1\ --api-module bot\ --configure-telegram-bot
#holyjs @slobodan_
#holyjs @slobodan_ PART 4. DEBUGGING
#holyjs @slobodan_ George Orwell English novelist
#holyjs @slobodan_ const botBuilder = require('claudia-bot-builder') module.exports = botBuilder(message =>
{ console.log(message) return 'Hello from HolyJS bot! You sent: ' + message.text }, { platforms: ['telegram'] }) bot.js file:
#holyjs @slobodan_ $ claudia update
#holyjs @slobodan_
#holyjs @slobodan_ MESSAGE OBJECT
#holyjs @slobodan_ • text • sender • type • originalRequest
• postback
#holyjs @slobodan_ PART 5. SEND MESSAGE / REPLY
#holyjs @slobodan_ William Shakespeare English poet
#holyjs @slobodan_ const botBuilder = require('claudia-bot-builder') module.exports = botBuilder(message =>
{ console.log(message) return 'Hello from HolyJS bot! You sent: ' + message.text }, { platforms: ['telegram'] }) bot.js file:
#holyjs @slobodan_ SIMPLY RETURN TO REPLY
#holyjs @slobodan_ BUT WHAT ABOUT ASYNC REPLIES?
#holyjs @slobodan_ const botBuilder = require('claudia-bot-builder') module.exports = botBuilder(message =>
{ return new Promise(resolve => { setTimeout(() => { resolve('Delayed reply ;)') }, 2000) }) }, { platforms: ['telegram'] }) bot.js file:
#holyjs @slobodan_ IS IT POSSIBLE TO REPLY WITH MULTIPLE MESSAGES?
#holyjs @slobodan_ NO!
#holyjs @slobodan_ JUST KIDDING OF COURSE IT IS!
#holyjs @slobodan_ const botBuilder = require('claudia-bot-builder') module.exports = botBuilder(message =>
{ console.log(message) return [ 'Hello from HolyJS bot!', `You sent: ${message.text}` ] }, { platforms: ['telegram'] }) bot.js file:
#holyjs @slobodan_ PART 6. CUSTOM KEYBOARDS AND ATTACHMENTS
#holyjs @slobodan_ Coco Chanel French fashion designer
#holyjs @slobodan_ require('claudia-bot-builder').telegramTemplate
#holyjs @slobodan_ bot.js file: const botBuilder = require('claudia-bot-builder') const telegramTemplate
= botBuilder. telegramTemplate module.exports = botBuilder(message => { console.log(message) return new telegramTemplate.Text('Hello') .addReplyKeyboard([['Schedule'], ['Info']]) .get() }, { platforms: ['telegram'] })
#holyjs @slobodan_
#holyjs @slobodan_ • Text messages • Custom Keyboard • Photo
messages • Audio messages • Location messages • Venue messages • Stickers • Change chat action • Pause between messages
#holyjs @slobodan_ FORMATTED MESSAGES DOCS: http://bit.ly/claudia-telegram
#holyjs @slobodan_ PART 7. BOT FLOW
#holyjs @slobodan_ J. R. R. Tolkien English writer
#holyjs @slobodan_ YOUR BOT NEEDS A STORYLINE
#holyjs @slobodan_ const botBuilder = require('claudia-bot-builder') module.exports = botBuilder(message =>
{ console.log(message) if (message.text === ‘/start' || message.text === ‘/start start') return 'Hello, I am Igor, HolyJS bot’ return `You sent: ${message.text}` }, { platforms: ['telegram'] }) bot.js file:
#holyjs @slobodan_ • Schedule info • Current and next talk
info • Conference info • Tweet with #holyjs • Help
#holyjs @slobodan_ #holyjs @slobodan_
#holyjs @slobodan_ IS THERE A BETTER WAY?
#holyjs @slobodan_ PART 8. SAVE THE STATE
#holyjs @slobodan_ Joan de Arc Heroine of France
#holyjs @slobodan_ DYNAMO DB
#holyjs @slobodan_ $ aws dynamodb create-table --table-name holyjs-state \ --attribute-definitions
\ AttributeName=userId,AttributeType=S \ --key-schema AttributeName=userId,KeyType=HASH \ --provisioned-throughput \ ReadCapacityUnits=1,WriteCapacityUnits=1 \ --query TableDescription.TableArn --output text
#holyjs @slobodan_ DynamoDB Policy { "Version": "2012-10-17", "Statement": [ {
"Action": [ "dynamodb:GetItem", "dynamodb:UpdateItem", "dynamodb:PutItem", "dynamodb:Scan" ], "Effect": "Allow", "Resource": "*" } ] }
#holyjs @slobodan_ const botBuilder = require('claudia-bot-builder') const api = botBuilder((message,
originalApiRequest) => { return 'Hello from HolyJS bot! You sent: ' + message.text }, { platforms: ['telegram'] }) api.addPostDeployConfig('dynamoDbTable', 'DynamoDB:', 'configure-bot') module.exports = api bot.js file:
#holyjs @slobodan_ const AWS = require('aws-sdk') const docClient = new
AWS.DynamoDB.DocumentClient()
#holyjs @slobodan_ const params = { TableName: originalApiRequest.env.dynamoDbTable, Key: {
userId: id } } return docClient.get(params).promise() .then(result => console.log('OK', result.Item))
#holyjs @slobodan_ return docClient.get(params).promise() .then(result => console.log('OK', result.Item)) .catch(err =>
{ params = { TableName: originalApiRequest.env.dynamoDbTable, Item: { userId: message.sender } } return docClient.put(params).promise() .then(res => console.log('Create', res)) })
#holyjs @slobodan_ PART 9. MULTILANGUAGE
#holyjs @slobodan_ Mark Twain American author and humorist
#holyjs @slobodan_ EASIEST SOLUTION: SAVE LANGUAGE SETTINGS IN THE STATE
(DYNAMO DB)
#holyjs @slobodan_ #holyjs @slobodan_
#holyjs @slobodan_ PART 10. SCHEDULED NOTIFICATIONS
#holyjs @slobodan_ John Lennon English singer and songwriter
#holyjs @slobodan_ FOR NOTIFICATIONS: CLOUD WATCH SCHEDULED EVENTS
#holyjs @slobodan_
#holyjs @slobodan_ WE WILL USE A NEW LAMBDA FUNCTION
#holyjs @slobodan_ BUT OUR TELEGRAM TOKEN IS IN THE API
GATEWAY STAGE VARIABLES!
#holyjs @slobodan_ A FEW SOLUTIONS: • AWS Lambda environment variables
• Save the token in DynamoDB / State • Pass the token in the event
#holyjs @slobodan_ #holyjs @slobodan_
#holyjs @slobodan_ PART 11. NLP AND AI
#holyjs @slobodan_ H. P. Lovecraft American writer of horror fiction
#holyjs @slobodan_ BUTTONS ARE COOL, BUT…
#holyjs @slobodan_ API.AI WIT.AI LUIS.AI IBM WATSON
#holyjs @slobodan_ LET’S MAKE OUR BOT SMARTER WITH API.AI
#holyjs @slobodan_
#holyjs @slobodan_
#holyjs @slobodan_
#holyjs @slobodan_
#holyjs @slobodan_
#holyjs @slobodan_
#holyjs @slobodan_ #holyjs @slobodan_
#holyjs @slobodan_ SHOW TIME!
#holyjs @slobodan_ Salvador Dali Spanish surrealist painter
#holyjs @slobodan_
#holyjs @slobodan_ LIVE BOT: telegram.me/holyjs_bot
#holyjs @slobodan_ OR Julius Caesar Roman statesman and general
#holyjs @slobodan_ SOURCE CODE: STOJANOVIC/HOLYJS-BOT
#holyjs @slobodan_ SEND PR TO ADD NEW SKILLS: https://github.com/stojanovic/holyjs-bot
#holyjs @slobodan_ CLAUDIA BOT BUILDER CLAUDIAJS/CLAUDIA-BOT-BUILDER
#holyjs @slobodan_ THE END Marilyn Monroe American actress
#holyjs @slobodan_ QUESTIONS TIME @SLOBODAN_ #HOLYJS Erwin Schrödinger Nobel Prize-winning
Austrian physicist