예제 #1
0
        private async Task ResumeAfterCommonResponseDialog(IDialogContext context, IAwaitable <CommonResponseResult> result)
        {
            var messageHandled = await result as CommonResponseResult;

            if (messageHandled != null && messageHandled.IsMessageHandled && messageHandled.Message.ToLower().Contains("animals"))
            {
                context.Call(new BasicQnAMakerDialog(), ResumeAfterQnaMakerDialog);
                await context.PostAsync(MessageUtility.GetWelcomeOptionsMessage((Activity)context.Activity, "Are you looking for"));
            }
        }
        public static IForm <RetailerFinderFormDialog> BuildForm()
        {
            OnCompletionAsyncDelegate <RetailerFinderFormDialog> processOrder = async(context, state) =>
            {
                // call service api and get the Retailers
                var retailers = await GetRetailerFinderApiResponse(state.Location);

                var messageActivity = CreateRetailerMessage(context, retailers);
                state.ResultCount = retailers.ResultCount;
                if (retailers.ResultCount > TakeResultCount)
                {
                    await context.PostAsync(MessageUtility.GetSimpleTextMessage(context.MakeMessage(), $"Here is the list of top {TakeResultCount} nearest locations..."));
                }
                await context.PostAsync(messageActivity);
            };

            return(new FormBuilder <RetailerFinderFormDialog>()
                   .Field(nameof(Location))
                   .OnCompletion(processOrder)
                   .Build());
        }
예제 #3
0
        private async Task ResumeAfterFormDialog(IDialogContext context, IAwaitable <object> result)
        {
            RetailerFinderFormDialog msgResult = null;

            try
            {
                msgResult = (RetailerFinderFormDialog)await result;
            }
            catch (Exception)
            {
            }

            if (msgResult != null && msgResult.ResultCount > 0)
            {
                await context.PostAsync(MessageUtility.GetWelcomeOptionsMessage((Activity)context.Activity.AsMessageActivity(), "Hope you find your retailers. Please select if you are looking for FAQ"));
            }
            else
            {
                await context.PostAsync(MessageUtility.GetWelcomeOptionsMessage((Activity)context.Activity.AsMessageActivity(), $"We could not find retailers for your location. Please try with another Zip/City/State by selecting 'Retailer Finder'."));
            }

            context.Wait(MessageReceivedAsync);
        }
예제 #4
0
        public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            var message = await result;

            try
            {
                if (message.Text.ToLower().Contains("retailer finder"))
                {
                    try
                    {
                        await context.Forward(Chain.From(() => FormDialog.FromForm(RetailerFinderFormDialog.BuildForm)), ResumeAfterFormDialog, message, CancellationToken.None);
                    }
                    catch (Exception)
                    {
                        await context.PostAsync(MessageUtility.GetWelcomeOptionsMessage((Activity)context.Activity.AsMessageActivity(), $"We could not find retailers for your location. Please try with another Zip/City/State by selecting 'Retailer Finder'."));

                        context.Wait(MessageReceivedAsync);
                    }
                }
                else if (message.Text.ToLower().Contains("faq"))
                {
                    await context.PostAsync(MessageUtility.GetSimpleTextMessage(context.MakeMessage(), "Please enter your question"));

                    await context.Forward(new BasicQnAMakerDialog(), ResumeAfterQnaMakerDialog, message, CancellationToken.None);
                }
                else
                {
                    await context.Forward(new CommonResponsesDialog(), ResumeAfterCommonResponseDialog, message, CancellationToken.None);
                }
            }
            catch (Exception ex)
            {
                //await context.PostAsync(ex.Message);
                //context.Wait(MessageReceivedAsync);
            }
        }
예제 #5
0
        public async Task HandleNo(IDialogContext context, string messageText)
        {
            var messageActivity = context.MakeMessage();

            messageActivity.Attachments = new List <Attachment>();
            AdaptiveCard card = new AdaptiveCard();

            card.Body.Add(new TextBlock()
            {
                Text   = "If you are looking for something else, you can always navigate to the following link:",
                Size   = TextSize.Large,
                Weight = TextWeight.Normal,
                Wrap   = true
            });

            // Add buttons to the card.
            card.Actions.Add(new OpenUrlAction()
            {
                Url   = "http://tst2.purinamills.com/",
                Title = "Purina FAQ",
            });

            Attachment attachment = new Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content     = card
            };

            messageActivity.Attachments.Add(attachment);

            await context.PostAsync(messageActivity);

            await context.PostAsync(MessageUtility.GetWelcomeOptionsMessage((Activity)messageActivity, "Or you can always search for FAQ's by selecting FAQ"));

            context.Wait(MessageReceived);
        }
예제 #6
0
        public async Task StartAsync(IDialogContext context)
        {
            await context.PostAsync(MessageUtility.GetCustomerCareMessage(context.MakeMessage()));

            context.Wait(MessageReceivedAsync);
        }
예제 #7
0
        public async Task HandleThanks(IDialogContext context, string messageText)
        {
            await context.PostAsync(MessageUtility.GetThanksMessage(context.MakeMessage(), ""));

            context.Wait(MessageReceived);
        }
예제 #8
0
        public async Task HandleGoodbye(IDialogContext context, string messageText)
        {
            await context.PostAsync(MessageUtility.GetSimpleTextMessage(context.MakeMessage(), "Bye. Looking forward to our next awesome conversation already."));

            context.Wait(MessageReceived);
        }
예제 #9
0
        public async Task HandleGreeting(IDialogContext context, string messageText)
        {
            await context.PostAsync(MessageUtility.GetWelcomeOptionsMessage((Activity)context.Activity, Resources.ChatBot.GreetingsMessage));

            context.Wait(MessageReceived);
        }