Beispiel #1
0
        public static async Task <HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log, IAsyncCollector <string> alexaAskTeenagerRequestQueue)
        {
            log.Info($"Request={req}");

            string teenagerType = req.GetQueryNameValuePairs()
                                  .FirstOrDefault(q => string.Compare(q.Key, "type", true) == 0)
                                  .Value;

            string cardTitle = "Teenager Says";

            switch (teenagerType)
            {
            case "daughter":
                cardTitle = "Teenage Daughter";
                break;

            case "son":
                cardTitle = "Teenage Son";
                break;
            }

            var speechlet   = new AskTeenagerSpeechlet(log, alexaAskTeenagerRequestQueue, cardTitle);
            var getResponse = await speechlet.GetResponseAsync(req);

            var queueObject = $"{{[Request:{{{HttpHelpers.ToLogString(req)}}},Response:{{{HttpHelpers.ToLogString(getResponse)}}}]}}";
            await alexaAskTeenagerRequestQueue.AddAsync(queueObject);

            return(getResponse);
        }
Beispiel #2
0
        public static async Task <HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log, IAsyncCollector <string> alexaAskTeenagerRequestQueue)
        {
            log.Info($"Request={req}");

            var    queryParams  = req.GetQueryNameValuePairs();
            string teenagerType = queryParams
                                  .FirstOrDefault(q => string.Compare(q.Key, "type", true) == 0)
                                  .Value;

            string cardTitle = "Teenager Says";

            switch (teenagerType)
            {
            case "daughter":
                cardTitle = "Teenage Daughter";
                break;

            case "son":
                cardTitle = "Teenage Son";
                break;
            }

            var speechlet = new AskTeenagerSpeechlet(log, alexaAskTeenagerRequestQueue, cardTitle);

            string code = queryParams
                          .FirstOrDefault(q => string.Compare(q.Key, "BypassCode", true) == 0)
                          .Value;

            if (!string.IsNullOrEmpty(code) && code == System.Environment.GetEnvironmentVariable("BypassCode"))
            {
                speechlet.SkipValidation = true;
            }

            var getResponse = await speechlet.GetResponseAsync(req);

            var logObject   = new Utilities.HttpQueueObject(req, getResponse);
            var queueObject = JsonConvert.SerializeObject(logObject, logObject.SerializationSettings);
            await alexaAskTeenagerRequestQueue.AddAsync(queueObject);

            return(getResponse);
        }