首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将lambda函数链接到alexa技能工具包

将lambda函数链接到alexa技能工具包
EN

Stack Overflow用户
提问于 2018-02-14 12:04:36
回答 1查看 594关注 0票数 1

嗨,我创建了一个lambda函数,它可以使用主键回忆dynamodb表中的项。

这是我的代码

代码语言:javascript
复制
'use strict';

var AWS = require('aws-sdk');
var dclient = new AWS.DynamoDB.DocumentClient();

var getItems = (event, context, callback)=>{
    
    dclient.get(event.params,(error,data)=>{
        if(error){
            callback(null,"error occurerd");
        }
        else{
            callback(null,data);
        }
    });
};

exports.getItems = getItems;
//exportshandelrhandlergetItems = getItems;

它可以正常工作,但现在我要做的是设置它与alexa一起工作,这样我就可以让alexa查询我的表了。

有人能帮我解决这个问题吗?我创造了一种技能,所有的技能都有关联,但我不知道该如何做我的交互模型。

谢谢

这是我的意图模式

代码语言:javascript
复制
{
  "intents": [
    {
      "intent": "date"
    },
    {
      "intent": "AMAZON.CancelIntent"
    },
    {
      "intent": "AMAZON.HelpIntent"
    },
    {
      "intent": "AMAZON.StopIntent"
    },
    {
      "intent": "Cinema"
    },
    {
      "intent": "MyIntent"
    }
  ]
}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-14 15:32:41

请按照以下步骤,

  1. 转到https://developer.amazon.com/
  2. 用你的帐户登录
  3. 点击Alexa
  4. 点击“添加新技能”
  5. 填写“技能信息”和“交互模型”部分
  6. 在“配置”部分中提到Lambda如下所示,

请将下面的代码复制到Lambda函数中,只需说‘打开’您的技能名称‘,Alexa应该回答’欢迎来到Alexa的世界‘

代码语言:javascript
复制
exports.handler = (event, context, callback) => {
    try {

        var request = event.request;

        if (request.type === "LaunchRequest") {
            context.succeed(buildResponse({
                speechText: "Welcome to the world of Alexa",
                repromptText: "I repeat, Welcome to the world of Alexa",
                endSession: false
            }));
        }


        else if (request.type === "SessionEndedRequest") {
            options.endSession = true;
            context.succeed();
        }
        else {
            context.fail("Unknown Intent type")
        }



    } catch (e) {

    }


};

function buildResponse(options) {
    var response = {
        version: "1.0",
        response: {
            outputSpeech: {
                "type": "SSML",
                "ssml": `<speak><prosody rate="slow">${options.speechText}</prosody></speak>`
            },

            shouldEndSession: options.endSession
        }
    };

    if (options.repromptText) {
        response.response.reprompt = {
            outputSpeech: {
                "type": "SSML",
                "ssml": `<speak><prosody rate="slow">${options.repromptText}</prosody></speak>`
            }
        };
    }

    return response;
}

请在我的GitHub中找到一个示例(不使用Alexa ),

https://github.com/vnathv/alexa-myfortune/blob/master/MyFortune/Index.js

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48786828

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档