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

Google Assistant

Avatar for Dima Dima
December 01, 2018

Google Assistant

Avatar for Dima

Dima

December 01, 2018

More Decks by Dima

Other Decks in Programming

Transcript

  1. Webhook const agent = new WebhookClient({request, response}); const intentMap =

    new Map(); intentMap.set('start', start); … agent.handleRequest(intentMap);
  2. Webhook function start(agent) { agent.add("Hello! Nice to see you at

    DevFest!”); } function start(agent) { const conv = agent.conv(); conv.ask('Hello!...'); agent.add(conv); }
  3. Webhook const {Card, Suggestion, Text, Image, …} = require(‘dialogflow-fulfillment'); const

    {Button, Table, BrowseCarousel, Carousel, List, MediaObject, Image, Suggestions, …} = require("actions-on-google");
  4. Webhook agent.add(new Card({ title: 'DevFest', imageUrl: 'https://...', text: 'Warsaw. December

    1-2, 2018...', buttonText: 'Link', buttonUrl: 'https://warsaw.devfest.pl' }) );
  5. Webhook const conv = agent.conv(); conv.ask('Greetings from GDG Warsaw!'); const

    list = new List({ title: 'Schedule', items: { 'firstDay': { synonyms: ['beginning','saturday'], title: '1 December’, image: new Image({...}), }, 'secondDay': {...} } }); conv.ask(list); agent.add(conv);
  6. Helpers const {Confirmation} = require("actions-on-google"); function confirmation(agent) { const conv

    = agent.conv(); conv.ask(new Confirmation('Would you mind confirming...')); agent.add(conv); }
  7. Helpers function confirmationResponse(agent) { const conv = agent.conv(); const isConfirmationGranted

    = conv.arguments.parsed.input.CONFIRMATION; if (isConfirmationGranted) {...} else {...} ... }
  8. Helpers function dateTime(agent) { const conv = agent.conv(); const options

    = { prompts: { initial: 'When would you like to receive your tickets?', date: 'What day was that?', time: 'What time?', }, }; conv.ask(new DateTime(options)); agent.add(conv); }
  9. Helpers function datetimeReceived(agent) { const conv = agent.conv(); const date

    = conv.arguments.parsed.input.DATETIME.date; const time = conv.arguments.parsed.input.DATETIME.time; agent.add(conv); }
  10. Helpers function permission(agent) { const conv = agent.conv(); const options

    = { context: 'To greet you by name at the entrance at DevFest', permissions: ['NAME', 'DEVICE_PRECISE_LOCATION'], }; conv.ask(new Permission(options)); agent.add(conv); }
  11. Helpers function permissionConfirmation(agent, app) { const conv = agent.conv(); const

    isGranted = conv.arguments.parsed.input.PERMISSION; if (confirmationGranted) { const location = conv.device; const name = conv.name; if (name) ... if (location) ... } ... }C
  12. Helpers function deeplink(agent) { const conv = agent.conv(); const options

    = { destination: 'DevFest', url: 'devfest://warsaw', package: 'pl.devfest.warsaw', reason: 'handle this for you', }; }C
  13. Helpers function deeplink(agent) { const conv = agent.conv(); const options

    = { destination: 'DevFest', url: 'devfest://warsaw', package: 'pl.devfest.warsaw', reason: 'handle this for you', }; conv.ask('Great! looks like maybe we can do that in the app.'); conv.ask(new DeepLink(options)); agent.add(conv); }C
  14. Store const conv = agent.conv(); conv.data.zip = { events: 'DevFest

    Warsaw', reason: ['Cool community', 'Perfect organised', ...] };
  15. Store const conv = agent.conv(); conv.user.storage.zip = { events: 'DevFest

    Warsaw', reason: ['Cool community', 'Perfect organized', ...] };
  16. Store const conv = agent.conv(); conv.user.storage.zip = { events: 'DevFest

    Warsaw', reason: ['Cool community', 'Perfect organized', ...] }; conv.user.storage = {};