public override async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument)
        {
            var message = await argument;
            if (message.Text.ToLower() == "makeattachment")
            {
                var reply = context.MakeMessage();
                reply.Text = string.Format("{0}: You said {1}", this.count++, message.Text);

                reply.Attachments = new List<Attachment>();

                var actions = new List<CardAction>();
                for (int i = 0; i < 3; i++)
                {
                    actions.Add(new CardAction
                    {
                        Title = $"Button:{i}",
                        Value = $"Action:{i}", 
                        Type = ActionTypes.ImBack
                    });
                }
                reply.AttachmentLayout = AttachmentLayoutTypes.Carousel; 
                for (int i = 0; i < 5; i++)
                {
                    reply.Attachments.Add(
                         new HeroCard
                         {
                             Title = $"title{i}",
                             Images = new List<CardImage>
                            {
                                new CardImage
                                {
                                    Url = $"https://placeholdit.imgix.net/~text?txtsize=35&txt=image{i}&w=120&h=120"
                                }
                            },
                             Buttons = actions
                         }.ToAttachment()
                    );
                }
                await context.PostAsync(reply);
                context.Wait(MessageReceivedAsync);
            }
            else
            {
                await base.MessageReceivedAsync(context, argument);
            }
        }
        public override async Task MessageReceivedAsync(IDialogContext context, IAwaitable<Message> argument)
        {
            var message = await argument;
            if (message.Text.ToLower() == "makeattachment")
            {
                var reply = context.MakeMessage();
                reply.Text = string.Format("{0}: You said {1}", this.count++, message.Text);

                reply.Attachments = new List<Attachment>();

                var actions = new List<Microsoft.Bot.Connector.Action>();
                for (int i = 0; i < 3; i++)
                {
                    actions.Add(new Microsoft.Bot.Connector.Action
                    {
                        Title = $"Button:{i}",
                        Message = $"Action:{i}"
                    });
                }

                for (int i = 0; i < 10; i++)
                {
                    reply.Attachments.Add(new Attachment
                    {
                        Title = $"title{i}",
                        ContentType = "image/jpeg",
                        ContentUrl = $"https://placeholdit.imgix.net/~text?txtsize=35&txt=image{i}&w=120&h=120",
                        Actions = actions
                    });
                }
                await context.PostAsync(reply);
                context.Wait(MessageReceivedAsync);
            }
            else
            {
                await base.MessageReceivedAsync(context, argument);
            }
        }
Example #3
0
        private async Task CarDamageDescriptionDialogResumeAfter(IDialogContext context, IAwaitable <object> result)
        {
            var qnaInvoked = Convert.ToBoolean(await result);

            if (!qnaInvoked)
            {
                await context.PostAsync("Takk. Hvor er kjøretøyet nå?");

                context.Call(new WhereIsCarNowDialog(), WhereIsCarNowDialogResumeAfter);
            }
            else
            {
                context.Call(new BasicInputTextDialog("Takk. Hvilke synlige skader har kjøretøyet fått?"), CarDamageDescriptionDialogResumeAfter);
            }
        }
Example #4
0
 private async Task ResumeAfterRootDialog(IDialogContext context, IAwaitable <object> result)
 {
 }
Example #5
0
        public virtual async Task TextEntered(IDialogContext context, IAwaitable <string> argument)
        {
            var result = await argument;

            //call Luis with result text
            JObject jobj;

            using (HttpClient httpClient = new HttpClient())
            {
                var url            = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/c8264ce7-e050-41f6-abca-e281561c88b8?subscription-key=f02536e856a548f6a89fa27a7bafd5ec&timezoneOffset=60&verbose=true&q=";
                var responseString = await httpClient.GetStringAsync(url + result);

                jobj = JObject.Parse(responseString);
            }

            var topScoringIntent = jobj.SelectToken("topScoringIntent");
            var intent           = topScoringIntent.SelectToken("intent").ToString();
            var score            = topScoringIntent.SelectToken("score").ToString();

            var entities   = (JArray)jobj.SelectToken("entities");
            var entityList = new List <Entity>();

            for (var i = 0; i < entities.Count; i++)
            {
                entityList.Add(new Entity()
                {
                    Type  = entities[i].SelectToken("type").ToString(),
                    Child = entities[i].SelectToken("entity").ToString()
                });
            }

            //TODO: implement logic for multiple entities
            if (entityList.Count > 0)
            {
                var entity = entityList[0].Child;

                switch (intent)
                {
                case "Hilfe":
                    await context.PostAsync($"Hier hast du die Möglichkeit mich nach einer bestimmten Art von Informationsmedium zu fragen und die entstpechende Gesellschaftsform zu benennen.\n\n\n\n" +
                                            $"Beispielsweise \"Ich brauche Dokumente zur Aktiengesellschaft\",\n\n\"Zeig mir online Nachrichten zur GbR\" oder\n\n\"Ich brauche jemanden der mir zum Thema GmbH weiterhilft\".");

                    PromptDialog.Text(context, TextEntered, "Also? Wie kann ich behilflich sein?");
                    break;

                case "Ansprechpartner":
                    await Ansprechpartner(context, entity);

                    break;

                case "Dokumente":
                    await Dokumente(context, entity);

                    break;

                case "Link":
                    await Link(context, entity);

                    break;

                case "None":
                    await context.PostAsync($"Leider habe ich '{result}' nicht verstanden.");

                    context.Done("Returning from LuisDialog");
                    break;

                default:
                    await context.PostAsync($"Leider habe ich '{result}' nicht verstanden.");

                    context.Done("Returning from LuisDialog");
                    break;
                }
            }
            else
            {
                string Ansprechpartner       = "Ansprechpartner";
                string Dokumente             = "Dokumente";
                string Link                  = "Link";
                string Stock                 = "Stock";
                IEnumerable <string> choices = new List <string> {
                    Ansprechpartner, Dokumente, Link, Stock
                };
                PromptDialog.Choice(context, TextEntered, choices, "Ich kann folgene Informationen geben?", promptStyle: PromptStyle.Auto);
            }
        }
Example #6
0
 private async Task ResumeAfterOptionDialog(IDialogContext context, IAwaitable <object> result)
 {
     context.Wait(this.MessageReceivedAsync);
 }
Example #7
0
 private async Task CallBack(IDialogContext context, IAwaitable <object> result)
 {
     context.Done("");
 }
Example #8
0
 private Task AfterAnswerAsync(IDialogContext context, IAwaitable <IMessageActivity> result)
 {
     // wait for the next user message
     context.Wait(MessageReceived);
     return(Task.CompletedTask);
 }
Example #9
0
        /**
         * Child dialog to handle the activity when the VMConfigDialog is closed
         **/

        private async Task ChildDialogComplte(IDialogContext context, IAwaitable <object> result)
        {
            context.Done(this);
        }
Example #10
0
        /// <summary>
        /// Ask if the user wants to take a survey after the trivia game.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        private async Task AfterTrivia(IDialogContext context, IAwaitable <string> result)
        {
            await context.PostAsync("Thanks for playing!");

            PromptDialog.Confirm(context, AfterAskingAboutSurvey, "Would you like to take a survey?");
        }
Example #11
0
 private async Task AfterJoke(IDialogContext context, IAwaitable <string> result)
 {
     context.Wait(MessageReceivedAsync);
 }
Example #12
0
 private async Task ResumeAfterTranslate(IDialogContext context, IAwaitable <object> result)
 {
     await context.PostAsync("**(▀̿Ĺ̯▀̿ ̿)** - Ok, me fala o texto então...");
 }
Example #13
0
        public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> argument)
        {
            var        msg = await argument;
            AuthResult authResult;

            //先判斷個人資料中是否包含 登入驗證結果
            if (context.UserData.TryGetValue(ContextConstants.AuthResultKey, out authResult))
            {
                try
                {
                    string validated;
                    context.UserData.TryGetValue <string>(ContextConstants.MagicNumberValidated, out validated);
                    if (validated == "true")
                    {
                        //已輸入登入頁面的驗證碼,可以結束本 Dialog
                        context.Done($"謝謝 {authResult.UserName}. 您已登入系統. ");
                    }
                    else
                    {
                        //尚未登入頁面的驗證碼
                        var magicNumber = 0;
                        if (context.UserData.TryGetValue <int>(ContextConstants.MagicNumberKey, out magicNumber))
                        {
                            if (msg.Text == null)
                            {
                                await context.PostAsync(
                                    $"請輸入登入完成後的{ContextConstants.MagicNumberLength}位數字驗證碼");

                                context.Wait(this.MessageReceivedAsync);
                            }
                            else
                            {
                                if (msg.Text.Length >= ContextConstants.MagicNumberLength && magicNumber.ToString() == msg.Text.Substring(0, ContextConstants.MagicNumberLength))
                                {
                                    //驗證成功,將資訊寫到 UserData 之中,並結束本 Dialog
                                    context.UserData.SetValue <string>(ContextConstants.MagicNumberValidated, "true");
                                    context.Done($"謝謝 {authResult.UserName}. 您已登入系統. ");
                                }
                                else
                                {
                                    //驗證失敗,重新輸入一次
                                    await context.PostAsync($"驗證碼錯誤,請重新輸入登入完成後的{ContextConstants.MagicNumberLength}位數字驗證碼!");

                                    context.Wait(this.MessageReceivedAsync);

                                    //也可以讓user重新登入
                                    //context.UserData.RemoveValue(ContextConstants.AuthResultKey);
                                    //context.UserData.SetValue<string>(ContextConstants.MagicNumberValidated, "false");
                                    //context.UserData.RemoveValue(ContextConstants.MagicNumberKey);
                                    //await this.LogIn(context, msg);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                    context.UserData.RemoveValue(ContextConstants.AuthResultKey);
                    context.UserData.SetValue(ContextConstants.MagicNumberValidated, "false");
                    context.UserData.RemoveValue(ContextConstants.MagicNumberKey);
                    context.Done($"I'm sorry but something went wrong while authenticating.");
                }
            }
            else
            {
                await this.LogIn(context, msg);
            }
        }
        private async Task ResumeAfterTaskDialog(IDialogContext context, IAwaitable <object> result)
        {
            await context.PostAsync("how can i help you ?");

            context.Done(true);
        }
Example #15
0
        private async Task ActivityReceivedAsync(IDialogContext context, IAwaitable <object> result)
        {
            var activity = await result as Activity;
            var reply    = activity.CreateReply();

            reply.Attachments = new List <Attachment>();

            if (activity.Text.StartsWith("hi"))
            {
                reply.Attachments.Add(new Attachment()
                {
                    ContentUrl  = "https://media.giphy.com/media/AaA2UnCqV3RAY/giphy.gif",
                    ContentType = "image/png",
                    Name        = "hi.png"
                });
            }
            else if (activity.Text.StartsWith("who are you"))
            {
                HeroCard hc = new HeroCard()
                {
                    Title    = "Who am I?",
                    Subtitle = "I'm the bot!"
                };
                List <CardImage> images = new List <CardImage>();
                CardImage        ci     = new CardImage("https://bot-metrics.com/assets/bm-bot-1bd9cec04cf3dd15a17ab8f9d391c3ef9a5fcad5c87bfae82c7bc3a6e774c243.png");
                images.Add(ci);
                hc.Images = images;
                reply.Attachments.Add(hc.ToAttachment());
            }
            else if (activity.Text.StartsWith("help"))
            {
                List <CardImage> images = new List <CardImage>();
                CardImage        ci     = new CardImage("http://intelligentlabs.co.uk/images/IntelligentLabs-White-Small.png");
                images.Add(ci);
                CardAction ca = new CardAction()
                {
                    Title = "Visit Support",
                    Type  = "openUrl",
                    Value = "http://www.intelligentlabs.co.uk"
                };
                ThumbnailCard tc = new ThumbnailCard()
                {
                    Title    = "Need help?",
                    Subtitle = "Go to our main site support.",
                    Images   = images,
                    Tap      = ca
                };
                reply.Attachments.Add(tc.ToAttachment());
            }
            else if (activity.Text.StartsWith("login"))
            {
                List <CardAction> buttons = new List <CardAction>();
                CardAction        ca      = new CardAction()
                {
                    Title = "Sign In",
                    Type  = "signin",
                    Value = "https://www.facebook.com/"
                };
                buttons.Add(ca);
                SigninCard card = new SigninCard()
                {
                    Text    = "You need to sign in to use this",
                    Buttons = buttons
                };
                reply.Attachments.Add(card.ToAttachment());
            }

            await context.PostAsync(reply);

            context.Wait(ActivityReceivedAsync);
        }
Example #16
0
        private async Task ResumeAfterHotelServicesDialog(IDialogContext context, IAwaitable <object> result)
        {
            await context.PostAsync("Thank you. We're all done. What else can I do for you?");

            context.Done <object>(null);
        }
Example #17
0
 private async Task AfterAddressPrompt(IDialogContext context, IAwaitable <string> result)
 {
     this.currentAddress = await result;
     PromptDialog.Choice(context, this.AfterSelectToSaveAddress, this.saveOptionNames.Concat(new[] { Resources.SavedAddressDialog_NotThisTime }), this.saveAddressPrompt);
 }
Example #18
0
        // ---------------------------------------------------------------------------------------------------------------------------

        private async Task MostrarOpcoesParaDadorNaoRegistado(IDialogContext context, IAwaitable <string> result)
        {
            await context.PostAsync("Eis algumas tarefas em que te posso ajudar:\n" +
                                    "- Esclarecimento de dúvidas.");
        }
Example #19
0
 private async Task ThankYou(IDialogContext context, IAwaitable <bool> result)
 {
     bool   option  = await result;
     string message = $"Thank you for Insuring with us. The policy documents sent to your email";
     await context.PostAsync(message);
 }
Example #20
0
 private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result)
 {
     await context.PostAsync($"Some flow went wrong, type go to proceed");
 }
Example #21
0
 public async Task ItemReceived(IDialogContext context, IAwaitable <IMessageActivity> item)
 {
     await context.Forward(new DialogTwo(), DialogTwoDone, await item, CancellationToken.None);
 }
Example #22
0
 private async Task ResumeAfterOptionDialog(IDialogContext context, IAwaitable <object> result)
 {
     context.Done(2);
 }
Example #23
0
            public async Task ItemReceived(IDialogContext context, IAwaitable <IMessageActivity> item)
            {
                var msg = await item;

                context.Done(msg.Text);
            }
Example #24
0
 public virtual async Task LuisDialogAsync(IDialogContext context, IAwaitable <object> argument)
 {
     PromptDialog.Text(context, TextEntered, "Welche Informationen brauchst du zu welcher Form? \n\n(Gib 'Hilfe' für weitere Infomationen ein)");
 }
Example #25
0
 private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result)
 {
     var activity = await result as Activity;
     await context.Forward(new LanguageParseDialog(), ResumeAftelLuisDialog, activity, CancellationToken.None);
 }
Example #26
0
 private async Task Callback(IDialogContext context, IAwaitable <object> result)
 {
     context.Wait(MessageReceived);
 }
Example #27
0
 private async Task ResumeAftelLuisDialog(IDialogContext context, IAwaitable <object> result)
 {
     context.Wait(MessageReceivedAsync);
 }
Example #28
0
        private async Task ResumeAfterFlightsFormDialog(IDialogContext context, IAwaitable <FlightsQuery> result)
        {
            try
            {
                var searchQuery = await result;
                (IEnumerable <Card> cards, float price) = await GetCards(searchQuery);

                var response        = context.MakeMessage();
                var responseMessage = $"I found {cards.Count()} credit cards to make this trip free.";
                if (price > 0)
                {
                    responseMessage += $" Signing up for one of these cards will save you approximately ${price}!";
                }
                response.Text  = responseMessage;
                response.Speak = responseMessage;
                await context.PostAsync(response);

                var resultMessage = context.MakeMessage();
                resultMessage.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                resultMessage.Attachments      = new List <Attachment>();

                foreach (var card in cards)
                {
                    HeroCard heroCard = new HeroCard()
                    {
                        // Todo: images?
                        Title    = string.Format("{0} by {1}", card.Name, card.Issuer),
                        Subtitle = string.Format("Get {0} signup bonus by spending ${1} within {2} months.",
                                                 card.RewardProgram.Equals("Cash") ? "$" + card.Bonus : card.Bonus + " points/miles", card.MinimumSpend, card.DaysForMinSpend / 30),
                        Buttons = new List <CardAction>()
                        {
                            new CardAction()
                            {
                                Title = "More details",
                                Type  = ActionTypes.OpenUrl,
                                Value = $"https://www.bing.com/search?q=" + HttpUtility.UrlEncode(string.Format("{0} {1} credit card", card.Issuer, card.Name))
                            }
                        }
                    };

                    resultMessage.Attachments.Add(heroCard.ToAttachment());
                }

                await context.PostAsync(resultMessage);
            }
            catch (FormCanceledException ex)
            {
                var response = context.MakeMessage();
                await context.PostAsync(response);

                if (ex.InnerException == null)
                {
                    var cancelationMessage = "You have canceled the operation. Quitting from the FlightsDialog...";
                    response.Text  = cancelationMessage;
                    response.Speak = cancelationMessage;
                }
                else
                {
                    var errorSpeak = "Something went wrong in FlightsDialog. Please find the exception text below for guidance:";
                    var errorText  = $"{errorSpeak}\n{ex}";
                    response.Text  = errorText;
                    response.Speak = errorSpeak;
                }

                await context.PostAsync(response);
            }
            finally
            {
                context.Done <object>(null);
            }
        }
 private async Task AfterAnswerAsync(IDialogContext context, IAwaitable <IMessageActivity> result)
 {
     // wait for the next user message
     context.Wait(MessageReceivedAsync);
 }
Example #30
0
        private async Task IsSomethingElseToTellDialogResumeAfter(IDialogContext context, IAwaitable <object> result)
        {
            await context.PostAsync("Takk, da har vi fått skademeldingen din, og vi kommer til å kontakte deg i løpet av første arbeidsdag.");

            context.Done(this);
        }
Example #31
0
        private async Task AfterFAQDialog(IDialogContext context, IAwaitable <object> result)
        {
            var messageHandled = await result;

            context.Done <object>(null);
        }
Example #32
0
 public async Task StockPriceIntent(IDialogContext context, IAwaitable <IMessageActivity> message, LuisResult result)
 {
     await this.ShowLuisResult(context, result);
 }
Example #33
0
        public Awaiter(IAwaitable awaitable)
        {
            Contract.Requires(awaitable != null);

            m_awaitable = awaitable;
        }