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

Alexa Skill開発を加速する ask-utils / vuilt-kyoto-5

Alexa Skill開発を加速する ask-utils / vuilt-kyoto-5

vuilt kyoto vol.5のスライドです。

Hidetaka Okamoto

September 14, 2018
Tweet

More Decks by Hidetaka Okamoto

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ • Digitalcube Co. Ltd. • WordCamp Kyoto 2017࣮ߦҕ һ௕

    • AWS Samurai 2017 H i d e t a k a O k a m o t o #VUILT
  2. ask-sdkͰͷΠϯςϯτϋϯυϥʔͷॻ͖ํ const HelpIntentHandler = { canHandle (handlerInput) { return handlerInput.requestEnvelope.request.type

    === 'IntentRequest' && handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent' }, handle (handlerInput) { const speechText = 'This is example skill' return handlerInput.responseBuilder .speak(speechText) .reprompt(speechText) .withSimpleCard(SKILL_NAME, speechText) .getResponse() } } #VUILT
  3. ͜͜Λຖճॻ͘ͷ͕൥Θ͔ͬͨ͠ const HelpIntentHandler = { canHandle (handlerInput) { return handlerInput.requestEnvelope.request.type

    === 'IntentRequest' && handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent' }, handle (handlerInput) { const speechText = 'This is example skill' return handlerInput.responseBuilder .speak(speechText) .reprompt(speechText) .withSimpleCard(SKILL_NAME, speechText) .getResponse() } } #VUILT
  4. handlerInputͷத਎ΛΑ͠ͳʹνΣοΫͯ͘͠ΕΔ const { canHandle } = require('ask-utils') const HelpIntentHandler =

    { canHandle (handlerInput) { return canHandle(handlerInput, 'IntentRequest', 'AMAZON.HelpIntent') }, handle (handlerInput) { const speechText = 'This is example skill' return handlerInput.responseBuilder .speak(speechText) .reprompt(speechText) .withSimpleCard(SKILL_NAME, speechText) .getResponse() } } #VUILT
  5. getRandomMessage()ͰҰൃ const { getRandomMessage } = require('ask-utils') const errorMessages =

    [ 'I can not here what you say, please say again.', 'Please say again.', "I'm sorry, please tell me again" ] const message = getRandomMessage(errorMessages) #VUILT
  6. enqueueProgressiveResponseDirective()ͰҰൃ try { // ϓϩάϨογϒϨεϙϯεΛར༻͢Δ await enqueueProgressiveResponseDirective(handlerInput, ‘ݕࡧத') } catch

    (err) { // τϥϒϧ͕ൃੜͯ͠΋ɺॲཧΛܧଓͤ͞Δɻ console.log(err) } // ֎෦ͷ API ͱ઀ଓ͢Δ const content = await get() return responseBuilder.speak(content).getResponse() #VUILT
  7. aws-sdk & ask-utilsͰσʔλΛอଘ͢Δ const AWS = require('aws-sdk') const { getUserId

    } = require('ask-utils') const dynamoDB = new AWS.DynamoDB.DocumentClient() const TableName = 'MyExampleDB' const SaveProfileHandler = { … async handle(handlerInput) { const userId = getUserId(handlerInput) const params = { TableName, Item: { id: userId, } } await dynamoDB.put(params).promise() ... } } #VUILT
  8. aws-sdk & ask-utilsͰσʔλΛอଘ͢Δ const AWS = require('aws-sdk') const { getUserId

    } = require('ask-utils') const dynamoDB = new AWS.DynamoDB.DocumentClient() const TableName = 'MyExampleDB' const SaveProfileHandler = { … async handle(handlerInput) { const userId = getUserId(handlerInput) const params = { TableName, Item: { id: userId, } } await dynamoDB.put(params).promise() ... } } #VUILT
  9. aws-sdk & ask-utilsͰσʔλΛอଘ͢Δ const AWS = require('aws-sdk') const { getUserId

    } = require('ask-utils') const dynamoDB = new AWS.DynamoDB.DocumentClient() const TableName = 'MyExampleDB' const SaveProfileHandler = { … async handle(handlerInput) { const userId = getUserId(handlerInput) const params = { TableName, Item: { id: userId, } } await dynamoDB.put(params).promise() ... } } #VUILT