示例#1
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");


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

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

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

            dynamic data = await req.Content.ReadAsAsync <object>();

            name   = name ?? data?.name;
            course = course ?? data?.course;
            time   = time ?? data?.time;


            if (name == null || course == null || time == null)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body"));
            }
            else
            {
                DHBWAPIRequester requester = new DHBWAPIRequester("http://stuv-mosbach.de/survival/api.php?action=getLectures&course=" + course);
                PlanParser       p         = new PlanParser(requester.GetResponse());
                if (p.getLectures(time))
                {
                    return(req.CreateResponse(HttpStatusCode.OK, "Hallo " + name + ", Du hast den Kurs: " + course + " gewählt. Vorlesungen am " + time + ": " + p.getResult()));
                }
                else
                {
                    return(req.CreateResponse(HttpStatusCode.OK, "Hallo" + name + ", es gibt keine Vorlesungen an diesem Tag."));
                }
            }
        }
示例#2
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            // Simple Function
            // Get request body
            dynamic data = await req.Content.ReadAsAsync <object>();

            log.Info($"Content={data}");
            if (data.request.type == "LaunchRequest")
            {
                // default launch request, let's just let them know what you can do
                log.Info($"Default LaunchRequest made");
                return(DefaultRequest(req));
            }
            else if (data.request.type == "IntentRequest")
            {
                // Set name to query string or body data
                string intentName = data.request.intent.name;
                log.Info($"intentName={intentName}");
                switch (intentName)
                {
                case "GetVorlesungDayXIntent":
                    string   n1        = data.request.intent.slots["Day"].value;
                    DateTime dateValue = DateTime.Parse(n1);
                    string   time      = dateValue.ToString("dd.MM.yyyy");
                    log.Info(time);
                    DHBWAPIRequester requester = new DHBWAPIRequester("http://stuv-mosbach.de/survival/api.php?action=getLectures&course=" + "INF16A");
                    PlanParser       p         = new PlanParser(requester.GetResponse());
                    p.getLectures(time);
                    string result = p.getResult();

                    string subject = result.ToString();
                    return(req.CreateResponse(HttpStatusCode.OK, new
                    {
                        version = "1.0",
                        sessionAttributes = new { },
                        response = new
                        {
                            outputSpeech = new
                            {
                                type = "PlainText",
                                text = $"Du hast: {result.ToString()}."
                            },
                            card = new
                            {
                                type = "Simple",
                                title = "Alexa gibt dir deinen Vorlesungsplan der DHBW Mosbach.",
                                content = $"The result is {result.ToString()}."
                            },
                            shouldEndSession = true
                        }
                    }));

                // Add more intents and default responses
                default:
                    return(DefaultRequest(req));
                }
            }
            else
            {
                return(DefaultRequest(req));
            }
        }