Пример #1
0
        public virtual async Task ProcessSpAccessRequest(IDialogContext context, LuisResult luisResult)
        {
            var accessToken =
                await context.GetAccessToken(
                    ConfigurationManager.AppSettings[
                        "ActiveDirectory.ResourceId"]); //assuming graph api is the resource

            SpFormHandler formHandler = new SpFormHandler();
            IFormDialog <SharepointModel> formDialog = formHandler.GetFormDialog(luisResult.Entities, accessToken);

            context.Call(formDialog, OnFormComplete);
        }
Пример #2
0
        public async Task CreateMeme(IDialogContext context, LuisResult result)
        {
            int             memetype = 0;
            MemeCreateOrder order    = new MemeCreateOrder();

            memetype = await ExtractMemeTypeReccomendationFromResult(result);

            memetext = await Task.Run(() => ExtractMemeTextReccomendationFromResult(result));

            // got a memetype back from the reccomender? fill it in
            if (memetype != 0)
            {
                order.memeOptions = (PopularMemeTypes)memetype;
            }
            // got text back from the reccomendation engine? fill that in too
            if ((memetext.TopText != string.Empty) || (memetext.BottomText != string.Empty))
            {
                // check if the meme text entity reccomendations came back with anything.  If the user used pre-filling syntaxt intents
                // then we should just pass those in to the order
                order.toptext    = (memetext.TopText == String.Empty) ? null : memetext.TopText;
                order.bottomtext = (memetext.BottomText == String.Empty) ? null : memetext.BottomText;
            }

            // if at this point we have enough information to create the meme without prompts, we bypass
            // the interactive conversation and just go
            if (order.HasEnoughInformationToCreateMeme)
            {
                Activity reply = context.MakeMessage() as Activity;
                await CaptionService.GenerateResultForMemeCreate(memetype, memetext.TopText, memetext.BottomText, reply);

                await context.PostAsync(reply);

                context.Wait(MessageReceived);
            }
            // otherwise, spin the converation from where we are (starting from whatever point we're at)
            else
            {
                IFormDialog <MemeCreateOrder> createOrderDialog = MakeMemeCreateInteractiveDialog(order);
                context.Call(createOrderDialog, FinalizeMemeCreation);
            }
        }
Пример #3
0
        public async Task createReservationWithDialog(IDialogContext context, LuisResult result)
        {
            IFormDialog <ReservationDialog> tmp = MakeRootDialog();

            context.Call <ReservationDialog>(tmp, ReservationDataCollected);
        }
Пример #4
0
        public async Task MessageReceivedAsync(IDialogContext context, IAwaitable <Message> argument)
        {
            var message = await argument;

            string    resp  = "";
            LUISModel model = await GetEntityFromLUIS(message.Text);


            if (model.intents.Count() > 0)
            {
                switch (model.intents[0].intent)
                {
                case intent_hi:


                    await context.PostAsync("Hallo! Versuchen Sie: \"Wann kommt mein Paket?\"\n\noder: \"Liefere mein Paket zur nähesten Abholstation\"");

                    context.Wait(MessageReceivedAsync);
                    break;

                case intent_deliveryState:
                    var               start = "Graz";
                    var               dest  = "Am Europlatz 3, Vienna";
                    Message           msg   = new Message();
                    string            query = "http://dev.virtualearth.net/REST/v1/Imagery/Map/Road/Routes?wp.0=" + start + ";64;1&wp.1=" + dest + ";66;2&key=AgArU18mPZIHjbt9F0l5_StVXlcXITxAbGRYl07EEUzOLiXIRYLBzWAiBTeTYNcQ";
                    List <Attachment> a     = new List <Attachment>();
                    a.Add(new Attachment(contentUrl: query, contentType: "image/jpeg"));

                    msg.Attachments = a;

                    string   metaquery   = "http://dev.virtualearth.net/REST/V1/Routes/Driving?o=json&wp.0=" + start + "&wp.1=" + dest + "&key=AgArU18mPZIHjbt9F0l5_StVXlcXITxAbGRYl07EEUzOLiXIRYLBzWAiBTeTYNcQ";
                    string   s           = new WebClient().DownloadString(metaquery);
                    dynamic  meta        = JsonConvert.DeserializeObject(s);
                    string   seconds     = meta.resourceSets[0].resources[0].travelDuration;
                    TimeSpan time        = TimeSpan.FromSeconds(Double.Parse(seconds));
                    var      arrivalTime = DateTime.Now.Add(time);
                    msg.Text = "Ihr Paket befindet sich im Moment in " + start + " und \nwird um " + arrivalTime.ToString(@"HH\:mm") + " ankommen.";


                    PostAndWait(context, msg);
                    break;

                case intent_changeDelivery:
                    DateTime?when    = DateTime.Now;
                    var      hasDate = model.entities.Where(e => e.type == "builtin.datetime.time").FirstOrDefault();
                    if (hasDate != null)
                    {
                        var parser = new Chronic.Parser();

                        var span = parser.Parse(hasDate.entity);
                        if (span != null)
                        {
                            if (when.Value.Hour < 18)
                            {
                                PostAndWait(context, "Okay, Zustellung geändert auf " + when.Value.ToString(@"HH\:mm"));
                            }
                            else
                            {
                                PostAndWait(context, MakeMessage("http://dev.virtualearth.net/REST/V1/Imagery/Map/Road/Am%20Europlatz%20Vienna?mapLayer=TrafficFlow&key=AgArU18mPZIHjbt9F0l5_StVXlcXITxAbGRYl07EEUzOLiXIRYLBzWAiBTeTYNcQ",
                                                                 "Das ist leider nicht möglich. Ihr Paket wird zu ihrer nähesten Abholstation geliefert. Am Europlatz 3, Vienna"));
                            }


                            break;
                        }
                    }


                    PostAndWait(context, MakeMessage("http://dev.virtualearth.net/REST/V1/Imagery/Map/Road/Am%20Europlatz%20Vienna?mapLayer=TrafficFlow&key=AgArU18mPZIHjbt9F0l5_StVXlcXITxAbGRYl07EEUzOLiXIRYLBzWAiBTeTYNcQ",
                                                     "Ihr Paket wird zu ihrer nähesten Abholstation \ngelifiert. Am Europlatz 3, Vienna"));

                    break;

                case intent_findStation:
                    Message           m           = new Message();
                    string            q           = "http://dev.virtualearth.net/REST/V1/Imagery/Map/Road/Am%20Europlatz%20Vienna?mapLayer=TrafficFlow&key=AgArU18mPZIHjbt9F0l5_StVXlcXITxAbGRYl07EEUzOLiXIRYLBzWAiBTeTYNcQ";
                    List <Attachment> attachments = new List <Attachment>();
                    attachments.Add(new Attachment(contentUrl: q, contentType: "image/jpeg"));

                    m.Attachments = attachments;
                    m.Text        = "Die näheste Abholstation ist Am Europlatz 3, Vienna";

                    PostAndWait(context, m);
                    break;

                case intent_paketTarif:

                    List <EntityRecommendation> entities = new List <EntityRecommendation>();
                    //get land

                    IFormDialog <PaketTarif> tmp = MakeRootDialog(new PaketTarif(), entities: entities);
                    context.Call(tmp, PaketTarifComplete);
                    break;

                default:
                    PostAndWait(context, "Didn't get that");
                    break;
                }
            }
            else
            {
                PostAndWait(context, "Leider nicht verstanden");
            }
        }