Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dr. Strangelove or: How I Learned to Stop Worry...

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

More Decks by Slobodan Stojanović

Other Decks in Technology

Transcript

  1. #holyjs
 @slobodan_ I am Slobodan Stojanović CTO of Cloud Horizon

    and JS Belgrade Meetup organizer github.com/stojanovic twitter.com/slobodan_
  2. #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)
  3. #holyjs
 @slobodan_ • AWS Lambda (2014) • Google Cloud Functions

    (2016) • IBM OpenWhisk (2016) • Microsoft Azure Functions (2016)
  4. #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)
  5. #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:
  6. #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:
  7. #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:
  8. #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:
  9. #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:
  10. #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'] })
  11. #holyjs
 @slobodan_ • Text messages • Custom Keyboard • Photo

    messages • Audio messages • Location messages • Venue messages • Stickers • Change chat action • Pause between messages
  12. #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:
  13. #holyjs
 @slobodan_ • Schedule info • Current and next talk

    info • Conference info • Tweet with #holyjs • Help
  14. #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
  15. #holyjs
 @slobodan_ DynamoDB Policy { "Version": "2012-10-17", "Statement": [ {

    "Action": [ "dynamodb:GetItem", "dynamodb:UpdateItem", "dynamodb:PutItem", "dynamodb:Scan" ], "Effect": "Allow", "Resource": "*" } ] }
  16. #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:
  17. #holyjs
 @slobodan_ const params = { TableName: originalApiRequest.env.dynamoDbTable, Key: {

    userId: id } } return docClient.get(params).promise() .then(result => console.log('OK', result.Item))
  18. #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)) })
  19. #holyjs
 @slobodan_ A FEW SOLUTIONS: • AWS Lambda environment variables

    • Save the token in DynamoDB / State • Pass the token in the event