在c#服务中从Alexa请求中获取说出的意图和广告位类型

时间:2018-12-20 12:29:46

标签: c# amazon-web-services aws-lambda alexa alexa-skills-kit

我在AWS Lambda上运行了一个c#服务,FunctionHandler正确接收了请求,并区分了Launch类型和Intent类型。就像标题中一样,如何获得用户实际输入的内容?

该意图被称为“交换屏幕”,示例话语是“将屏幕切换到{display}”,并且自定义插槽具有“计算机”或“电视”选项。

如何选择“计算机”或“电视”?

private SkillResponse skillResponse = null;

    /// <summary>
    /// A simple function that takes a string and does a ToUpper
    /// </summary>
    /// <param name="input"></param>
    /// <param name="context"></param>
    /// <returns></returns>

    public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext ctx)
    {
        if (input.GetRequestType() == typeof(LaunchRequest))
        {
            skillResponse = LaunchRequestHandler(input);
        }
        else if (input.GetRequestType() == typeof(IntentRequest))
        {
            skillResponse = IntentRequestHandler(input);
        }


        return skillResponse;
    }

    private SkillResponse LaunchRequestHandler(SkillRequest skillRequest)
    {
        var skillResponse = new SkillResponse
        {
            Version = "1.0",
            Response = new ResponseBody()
        };

        skillResponse.Response.OutputSpeech = new PlainTextOutputSpeech
        {
            Text = "Launch."
        };

        return skillResponse;
    }

    private SkillResponse IntentRequestHandler(SkillRequest skillRequest)
    {
        var skillResponse = new SkillResponse
        {
            Version = "1.0",
            Response = new ResponseBody()
        };

        skillResponse.Response.OutputSpeech = new PlainTextOutputSpeech
        {
            Text = "Intent."
        };

        return skillResponse;
    }

谢谢。

1 个答案:

答案 0 :(得分:0)

在这里,我假设您在相同的意图/话语中可能有多个插槽。

Alexa请求会转换数组中的所有插槽值,因此您可以使用以下代码访问插槽值。(此处“ date”是我的插槽名称)

       if (intentRequest.Intent.Slots.TryGetValue("date", out var dateSlot))
            {
                if (!string.IsNullOrEmpty(dateSlot.Value))
                {
                   //Slot value
                }
            }