Alexa自定义技能有可能吗?

时间:2018-08-03 12:00:55

标签: alexa alexa-skills-kit alexa-voice-service alexa-slot alexa-app

我的问题是关于..

我创建了一种定制的Alexa技能,希望向用户提供以下功能:

  • 我的网络服务调用返回多个事件
  • 现在我要逐个播放这一系列事件,如果用户说下一步,那么当前事件将被跳过,下一事件将自动播放。
  • 否则,Alexa会逐一讲所有事件。
  • 在这里,用户可能会提供输入,也可能不会。因此,在这种情况下,用户输入是可选的。

有办法吗?

这是示例代码

if (null!= intentRequest.Intent.Slots[AlexaConstants.facilityQuery].Value && !"".Equals(intentRequest.Intent.Slots[AlexaConstants.facilityQuery].Value))
                        {
                            if (!"".Equals(getResolution(input, AlexaConstants.facilityQuery)))
                            {
                                HighwayEventsController apitransit = new HighwayEventsController();
                                log.LogLine(JsonConvert.SerializeObject(intentRequest));
                                var facilityQuery = getResolution(input, AlexaConstants.facilityQuery);
                                string highwayOutput = apitransit.GetHighwayEventsData(facilityQuery);
                                //(innerResponse as SsmlOutputSpeech).Ssml = $"<speak>{apitransit.GetHighwayEventsData(facilityQuery)}<break time='1s'/> {otherFacilityMsg}</speak>";
                                intentRequest.Intent.Slots[AlexaConstants.facilityQuery].Value = "";
                                intentRequest.Intent.Slots[AlexaConstants.choice].Value = "by name";
                                response.Response.Directives.Add(getDialogDirective(input, AlexaConstants.HighwayEventIntent, AlexaConstants.next));
                                response.Response.Reprompt = getReprompt("say next for next event, or say go to main menu  or say stop for exit");
                                string pattern = @"Event \d+";
                                string[] result = Regex.Split(highwayOutput, pattern);
                                string speak = result.Length > 0 ? result[0] + "Event 1 " + result[1] : highwayOutput;
                                innerResponse = new SsmlOutputSpeech();
                                (innerResponse as SsmlOutputSpeech).Ssml = $"<speak>{speak}<break time='500ms'/> say next for next event, or say go to main menu  or say stop for exit</speak>";
                                Dictionary<string, object> events = new Dictionary<string, object>();
                                for (int i = 2; i < result.Length; i++)
                                {
                                    events.Add("Event " + i, "Event " + i + " " + result[i]);
                                }
                                events.Add("currentVal", 2);
                                events.Add("TotalEvents", result.Length - 1);
                                response.SessionAttributes = events;
                            }
                            else
                            {
                                response.Response.Directives.Add(getDialogDirective(input, AlexaConstants.HighwayEventIntent, AlexaConstants.facilityQuery));
                                innerResponse = new PlainTextOutputSpeech();
                                (innerResponse as PlainTextOutputSpeech).Text = "Invalid Facility. please Provide facility name";
                            }
                        }

0 个答案:

没有答案