コード例 #1
0
        private async Task <SkillResponse> BuildMorningReportResponseAsync()
        {
            var response = await _dynamoClient.GetItemAsync(_dynamoTable, new Dictionary <string, AttributeValue> {
                ["Key"] = new AttributeValue {
                    S = MorningReportInfo.ROW_KEY
                }
            });

            AttributeValue value = null;

            if ((response.HttpStatusCode != HttpStatusCode.OK) || !response.Item.TryGetValue("Value", out value))
            {
                return(BuildSpeechResponse(PROMPT_ERROR_MORNING_REPORT));
            }
            var morningReport = MorningReportInfo.FromJson(value.S);

            return(new SkillResponse {
                Version = "1.0",
                Response = new ResponseBody {
                    OutputSpeech = new SsmlOutputSpeech {
                        Ssml = morningReport.ConvertContentsToSsml(_preHeadingBreak, _postHeadingBreak, _bulletBreak)
                    },
                    ShouldEndSession = true
                }
            });
        }
コード例 #2
0
ファイル: Function.cs プロジェクト: VOSD/AlexaVoiceOfSanDiego
        public async Task <bool> SaveMorningReportAsync(MorningReportInfo morningReport)
        {
            if (morningReport == null)
            {
                return(false);
            }
            var response = await _dynamoClient.PutItemAsync(_dynamoTable, new Dictionary <string, AttributeValue> {
                ["Key"] = new AttributeValue {
                    S = MorningReportInfo.ROW_KEY
                },
                ["Value"] = new AttributeValue {
                    S = morningReport.ToJson()
                },
                ["When"] = new AttributeValue {
                    S = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss")
                }
            });

            return(true);
        }
コード例 #3
0
        private async Task <SkillResponse> BuildWhatsNewResponseAsync()
        {
            var response = await _dynamoClient.BatchGetItemAsync(new Dictionary <string, KeysAndAttributes> {
                [_dynamoTable] = new KeysAndAttributes {
                    Keys = new List <Dictionary <string, AttributeValue> > {
                        new Dictionary <string, AttributeValue> {
                            ["Key"] = new AttributeValue {
                                S = PodcastInfo.ROW_KEY
                            }
                        },
                        new Dictionary <string, AttributeValue> {
                            ["Key"] = new AttributeValue {
                                S = MorningReportInfo.ROW_KEY
                            }
                        }
                    }
                }
            });

            List <Dictionary <string, AttributeValue> > rows;

            if ((response.HttpStatusCode != HttpStatusCode.OK) || !response.Responses.TryGetValue(_dynamoTable, out rows))
            {
                return(BuildSpeechResponse(PROMPT_ERROR_WHAT_IS_NEW));
            }
            MorningReportInfo morningReport = null;

            PodcastInfo[] podcasts = null;
            foreach (var row in rows)
            {
                try {
                    switch (row["Key"].S)
                    {
                    case MorningReportInfo.ROW_KEY:
                        morningReport = MorningReportInfo.FromJson(row["Value"].S);
                        break;

                    case PodcastInfo.ROW_KEY:
                        podcasts = PodcastInfo.FromJson(row["Value"].S);
                        break;

                    default:

                        // unexpected item; ignore it
                        break;
                    }
                } catch (Exception e) {
                    // log the exception and continue
                    LambdaLogger.Log($"*** ERROR: unable to parse item ({e})");
                }
            }
            if ((morningReport == null) && (podcasts == null))
            {
                return(BuildSpeechResponse(PROMPT_ERROR_WHAT_IS_NEW));
            }
            var news = new StringBuilder();

            if (morningReport != null)
            {
                news.AppendLine($"The latest morning report is from {morningReport.Date.ToString("dddd, MMMM d")}, and is entitled: \"{morningReport.Title}\".");
            }
            if ((podcasts != null) && (podcasts.Length > 0))
            {
                news.AppendLine($"The latest podcast was recorded {podcasts[0].Date.ToString("dddd, MMMM d")}, and is entitled: \"{podcasts[0].Title}\".");
            }
            return(BuildSpeechResponse(news.ToString() + PROMPT_HELP_QUESTION, shouldEndSession: false));
        }