Ejemplo n.º 1
0
        /// <summary>
        /// Fetches course details
        /// </summary>
        /// <param name="context"></param>
        /// <param name="activity"></param>
        /// <returns></returns>
        public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <BooleanChoice> activity)
        {
            try
            {
                var response = await activity;
                if (response.Equals(BooleanChoice.Yes))
                {
                    PromptDialog.Text(
                        context: context,
                        resume: ResumeGetFirstName,
                        prompt: "Sure. May I have your contact number or email address ?",
                        retry: "Sorry, I didn't understand that. Please try again."
                        );
                }
                else
                {
                    await context.PostAsync("Thanks for your valuable time !!!");

                    context.EndConversation(EndOfConversationCodes.CompletedSuccessfully);
                }
            }
            catch
            {
                await context.PostAsync("Thanks for your valuable time !!!");

                context.EndConversation(EndOfConversationCodes.CompletedSuccessfully);
            }
        }
Ejemplo n.º 2
0
        public virtual async Task ResumeGetFirstName(IDialogContext context, IAwaitable <string> Username)
        {
            string response = await Username;

            firstName = response;
            if (firstName.Equals("reset", StringComparison.InvariantCultureIgnoreCase))
            {
                context.EndConversation("End");
            }
            else if ((Regex.IsMatch(firstName, @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*")) || (Regex.IsMatch(firstName, @"^[0][1-9]\d{9}$|^[1-9]\d{9}$")))
            {
                string api = "/rest/learning/product/FetchCourseProduct";
                var    responseFromServer = await _restApiUtil.GetResponseFromServer(api);

                var serializer        = new JavaScriptSerializer();
                var courseProductList = serializer.Deserialize <List <CourseProduct> >(responseFromServer);
                var courseList        = courseProductList.Select(x => x.Name).ToList();

                PromptDialog.Choice(context, ChildDialogComplete, courseProductList.Select(x => x.Name), "What course are you interested to inquire for?", "Selected course not available. Please try again.", 3, PromptStyle.Auto, courseProductList.Select(x => x.Name));
            }
            else
            {
                PromptDialog.Text(
                    context: context,
                    resume: ResumeGetFirstName,
                    prompt: "Kindly share valid email address or contact number",
                    retry: "Sorry, I didn't understand that. Please try again."
                    );
            }
        }
Ejemplo n.º 3
0
        private async Task handleFinalIntent(IDialogContext context, IAwaitable <string> result)
        {
            var           foods  = await result;
            List <string> nolist = new List <string>();

            nolist.Add("no");
            nolist.Add("nope");
            nolist.Add("nay");
            nolist.Add("nothing");
            if (nolist.Contains(foods, StringComparer.OrdinalIgnoreCase))
            {
                await context.PostAsync("You can continue to order or exclude items from your order.");
            }
            else if (foods.Equals("yes"))
            {
                // context.Done("Thanks for ordering with HungryBelly. We'll get back with your order soon!");
                await context.SayAsync("Thank you for ordering with HungryBelly \\m/");

                context.EndConversation("");
            }
            else
            {
                await context.PostAsync("I didn't quite catch that. You can continue to order or exclude items from your order.");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets donation amount
        /// </summary>
        /// <param name="context"></param>
        /// <param name="response"></param>
        /// <returns></returns>
        public async Task ChildDialogComplete(IDialogContext context, IAwaitable <String> response)
        {
            var message = await response;

            donationType = message.ToString();
            if (donationType.Equals("reset", StringComparison.InvariantCultureIgnoreCase))
            {
                context.EndConversation("End");
            }
            else
            {
                List <string> amountList = new List <string>()
                {
                    "10", "50", "100", "1000"
                };

                PromptDialog.Choice(
                    context: context,
                    resume: ResumeGetDonationAmount,
                    options: amountList,
                    prompt: "How much amount would you like to donate in £?",
                    retry: "Selected amount not available. Please try again.",
                    promptStyle: PromptStyle.Auto
                    );
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets phone
        /// </summary>
        /// <param name="context"></param>
        /// <param name="mobile"></param>
        /// <returns></returns>
        public async Task ResumeGetPhone(IDialogContext context, IAwaitable <string> mobile)
        {
            string response = await mobile;

            phone = response;
            if (phone.Equals("reset", StringComparison.InvariantCultureIgnoreCase))
            {
                context.EndConversation("End");
            }
            else if (Regex.IsMatch(phone, @"^[0][1-9]\d{9}$|^[1-9]\d{9}$"))
            {
                string api = "/rest/learning/product/FetchDonationProduct";
                var    responseFromServer = await _restApiUtil.GetResponseFromServer(api);

                var serializer          = new JavaScriptSerializer();
                var donationProductList = serializer.Deserialize <List <DonationProduct> >(responseFromServer);

                PromptDialog.Choice(context, ChildDialogComplete, donationProductList.Select(x => x.Name), "We have number of donation options where you can make real difference. Please Select.", "Selected donation not available. Please try again.", 3, PromptStyle.Auto, donationProductList.Select(x => x.Name));
            }
            else
            {
                PromptDialog.Text(
                    context: context,
                    resume: ResumeGetPhone,
                    prompt: "Kindly share valid contact number",
                    retry: "Sorry, I didn't understand that. Please try again."
                    );
            }
        }
Ejemplo n.º 6
0
        private async Task ChoiceMade(IDialogContext context, IAwaitable <string> argument)
        {
            var result = await argument;

            switch (result)
            {
            case Diff:
                await context.Forward(new DiffDialog(), RootDialogAsync, "", CancellationToken.None);

                break;

            case Information:
                await context.Forward(new LuisDialog(), RootDialogAsync, "", CancellationToken.None);

                break;

            case Question:
                await context.Forward(new QnADialog(), RootDialogAsync, "", CancellationToken.None);

                break;

            case Exit:
                await context.PostAsync("Gerne, bis bald!");

                context.EndConversation("0");
                break;
            }
        }
Ejemplo n.º 7
0
        public virtual async Task Final(IDialogContext context, IAwaitable <string> Password)
        {
            password = await Password;

            if (cancelTerms.Contains(password.ToLower()))
            {
                await context.PostAsync("Login cancelled!");

                context.EndConversation("Login cancelled by user.");
            }
            else if (CheckLogin())
            {
                LuisDialog.user = user;
                await context.PostAsync("You are now logged in!");

                context.Done(this);
            }
            else if (!CheckUsername())
            {
                await context.PostAsync("Username does not exist!\n\nPlease try again...");

                context.Call <object>(new LoginDialog(userList), LoginComplete);
            }
            else
            {
                await context.PostAsync("Username and password do not match!\n\nPlease try again...");

                context.Call <object>(new LoginDialog(userList), LoginComplete);
            }
        }
Ejemplo n.º 8
0
        async Task DoSearch(IDialogContext context, WineForm wineInfo)
        {
            int wineType =
                (from refinement in WineCategories
                 where refinement.Name == wineInfo.WineType
                 select refinement.Id)
                .SingleOrDefault();

            List[] wines =
                await new WineApi().SearchAsync(
                    wineType,
                    wineInfo.Rating,
                    wineInfo.InStock == StockingType.InStock,
                    wineInfo.SearchTerms);

            string message;

            if (wines.Any())
            {
                message = "Here are the top matching wines: " +
                          string.Join(", ", wines.Select(w => w.Name));
            }
            else
            {
                message = "Sorry, No wines found matching your criteria.";
            }

            await context.PostAsync(message);

            context.EndConversation(EndOfConversationCodes.CompletedSuccessfully);
        }
Ejemplo n.º 9
0
        private async Task FinishRegistration(IDialogContext context)
        {
            try
            {
                await FireBaseHelper.registerUserInFireBase(new User
                {
                    email = context.PrivateConversationData.GetValue <string>("email")
                    ,
                    // lastname = context.PrivateConversationData.GetValue<string>("LastName")
                    //  ,
                    nickname = context.PrivateConversationData.GetValue <string>("nickname")
                });

                await context.PostAsync($"Registration successfull with following details: ");

                foreach (string key in questions.Keys)
                {
                    await context.SayAsync($"{key}: {context.PrivateConversationData.GetValue<string>(key)}",
                                           $"{key}: {context.PrivateConversationData.GetValue<string>(key)}");

                    //await context.PostAsync($"{key}: { context.PrivateConversationData.GetValue<string>(key)}");
                }
                context.EndConversation("Conversation Ended");
            }
            catch (Exception e)
            {
                await context.PostAsync($"Error occured: {e.Message}");
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Gets email
        /// </summary>
        /// <param name="context"></param>
        /// <param name="UserEmail"></param>
        /// <returns></returns>
        public virtual async Task ResumeGetEmail(IDialogContext context, IAwaitable <string> UserEmail)
        {
            string response = await UserEmail;

            email = response;

            if (email.Equals("reset", StringComparison.InvariantCultureIgnoreCase))
            {
                context.EndConversation("End");
            }
            else if (Regex.IsMatch(email, @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"))
            {
                PromptDialog.Text(
                    context: context,
                    resume: ResumeGetPhone,
                    prompt: "Please share your contact number",
                    retry: "Sorry, I didn't understand that. Please try again.");
            }
            else
            {
                PromptDialog.Text(
                    context: context,
                    resume: ResumeGetEmail,
                    prompt: "Kindly provide valid email address? We don't spam",
                    retry: "Sorry, I didn't understand that. Please try again."
                    );
            }
        }
Ejemplo n.º 11
0
        private async Task resume(IDialogContext context, IAwaitable <string> result)
        {
            var userName = await result;

            if (userName.Contains("@") || userName.Contains(" ") || userName.ToUpper().Equals("PYDGN"))
            {
                await context.PostAsync("Your username is Invalid.Please enter one without spaces or the @ symbol");
                await StartAsync(context);
            }
            else if (await Program.MakeUser(userName, context.Activity.Conversation.Id, "messenger") == false)
            {
                //username is already taken
                await context.PostAsync("The username is already taken. Please enter a different username!");
                await StartAsync(context);

                context.EndConversation("");
            }
            //
            // context.Activity.Conversation.Id

            // check with the backend if unique
            else
            {
                context.PostAsync($"Cool! Your new username is '@{userName}'. When you send a message, format it with  \"@username message...\"");
                context.Done(context);
            }
        }
Ejemplo n.º 12
0
        private async Task ConfirmationExit(IDialogContext context, IAwaitable <bool> result)
        {
            // result is yes if the user choose yes, otherwive Result is false
            if (result != null)
            {
                if (await result)
                {
                    //Bot will responses with this message
                    await context.PostAsync("Good Bye");

                    // Close conversation
                    context.EndConversation("end of conversation");
                }
                else
                {
                    try {
                        //
                        await context.PostAsync("Ok");

                        context.Done <string>(null);
                        // Bot will redirect the user to our Master Dialog
                        await context.Forward(new MasterDialog(), null, null, CancellationToken.None);
                    } catch (Exception e) { }
                }
            }
        }
Ejemplo n.º 13
0
        private async Task FinallyGreet(IDialogContext context, IAwaitable <string> result)
        {
            try
            {
                string message = string.Empty;

                if (isChiefGuest)
                {
                    message = "Thank you for being here with us today. Please enjoy.";
                }
                else
                {
                    message = $"Thank you for visiting CEM stall {name} Please enjoy.";
                }
                await context.SayAsync(message);
            }
            catch (TooManyAttemptsException)
            {
                await context.SayAsync(retryMessage);
            }
            finally
            {
                context.EndConversation("end");
            }
        }
        // Send response
        private async Task SendResponse(IDialogContext context, Response response)
        {
            IMessageActivity message;

            // Ensure original translation
            response.Message = await TranslationUtil.ReverseFromSpanishTranslation(response.Message, _info.Locale);

            // Build message
            switch (_info.ChannelId)
            {
            case Constants.Channels.DirectLine:
                message = await BuildDirectLineMessage(context, response);

                break;

            case Constants.Channels.WebChat:
            default:
                message = await BuildDefaultMessage(context, response);

                break;
            }

            // Send message
            await context.PostAsync(message);

            if (response.EndConversation)
            {
                context.EndConversation(EndOfConversationCodes.CompletedSuccessfully);
            }
            else
            {
                context.Wait(MessageReceived);
            }
        }
Ejemplo n.º 15
0
        public async Task CarSlower(IDialogContext context, LuisResult result)
        {
            await IoTHelper.SendAsync("s-20");

            await context.PostAsync($"Pressing the brake");

            context.EndConversation("Conversation Ended");
        }
Ejemplo n.º 16
0
        public async Task CarFaster(IDialogContext context, LuisResult result)
        {
            await IoTHelper.SendAsync("s+20");

            await context.PostAsync($"Vroooom, the car goes faster");

            context.EndConversation("Conversation Ended");
        }
Ejemplo n.º 17
0
        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> message)
        {
            // send a message to user confirming their cancel request
            await context.PostAsync(Properties.Resources.CANCEL_CONFIRMATION);

            // end the conversation (clearing the state and dialog stack)
            context.EndConversation(EndOfConversationCodes.UserCancelled);
        }
Ejemplo n.º 18
0
        public async Task CarStop(IDialogContext context, LuisResult result)
        {
            await IoTHelper.SendAsync("s0");

            await context.PostAsync($"Car halted !!");

            context.EndConversation("Conversation Ended");
        }
Ejemplo n.º 19
0
        public static async Task HandleTooManyAttempts(IDialogContext context)
        {
            await context.PostAsync("Det ser ut til at jeg ikke hjelper deg.");

            await context.PostAsync("Jeg skal begynne igjen.");

            context.EndConversation("TooManyAttempts");
        }
Ejemplo n.º 20
0
        public async Task StartAsync(IDialogContext context)
        {
            await context.PostAsync("Sorry!!!. I couldn't help you much this time. You can try to start it over again and check...");

            context.EndConversation("Get Lost.");

            //context.Wait(this.MessageReceived);
        }
        public async Task None(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result)
        {
            // send a message to the user indicating the request was not recognized
            await context.PostAsync(Properties.Resources.NONE);

            // end the conversation
            context.EndConversation(EndOfConversationCodes.Unknown);
        }
        public async Task CreateReservation(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result)
        {
            await context.PostAsync("Looks like your attempting to create a reservation.  Let's see what information we were able to pull");

            // attempt to parse the location from the request if provided by the user
            if (result.TryFindEntity("RestaurantReservation.Address", out var locationRecommendation))
            {
                context.PrivateConversationData.SetValue("LOCATION", locationRecommendation.Entity);
            }

            // attempt to parse a cuisine from the luis result if provided by the user
            if (result.TryFindEntity("RestaurantReservation.Cuisine", out var cuisineRecommendation))
            {
                context.PrivateConversationData.SetValue("CUISINE", cuisineRecommendation.Entity);
            }

            // attempt to parse the date time if provided by the user
            if (result.TryFindDateTime("builtin.datetimeV2.datetime", out var when))
            {
                context.PrivateConversationData.SetValue("WHEN", when.Value.ToString());
            }

            // attempt to parse the number of people if provided by the user
            if (result.TryFindInteger("builtin.number", out var partySize))
            {
                context.PrivateConversationData.SetValue("PARTY_SIZE", partySize.Value);
            }

            // reply with the parsed location if we saved in state
            if (context.PrivateConversationData.ContainsKey("LOCATION"))
            {
                await context.PostAsync($"Location Preference:  {context.PrivateConversationData.GetValueOrDefault<string>("LOCATION")}");
            }

            // reply with the parsed cuisine if we saved in state
            if (context.PrivateConversationData.ContainsKey("CUISINE"))
            {
                await context.PostAsync($"Cuisine Preference:  {context.PrivateConversationData.GetValueOrDefault<string>("CUISINE")}");
            }

            // reply with the parsed date / time if we saved in state
            if (context.PrivateConversationData.ContainsKey("WHEN"))
            {
                await context.PostAsync($"Date Preference:  {context.PrivateConversationData.GetValueOrDefault<DateTime>("WHEN")}");
            }

            // reply with the parsed number of people if saved in state
            if (context.PrivateConversationData.ContainsKey("PARTY_SIZE"))
            {
                await context.PostAsync($"Party Size Preference:  {context.PrivateConversationData.GetValueOrDefault<int>("PARTY_SIZE")}");
            }

            // end the conversation
            context.EndConversation(EndOfConversationCodes.CompletedSuccessfully);
        }
        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            var reply = context.MakeMessage();

            reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
            reply.Attachments      = GetHeroCardAttachments();

            await context.PostAsync(reply);

            context.EndConversation("");
        }
Ejemplo n.º 24
0
        private async Task ReservationConfirmedAsync(IDialogContext context, IAwaitable <Reservation> response)
        {
            // we received confirmation from the reservation confirmation dialog!
            var reservation = await response;

            // send information to the user with their confirmation details
            var text = string.Format(Properties.Resources.BOOKED_CONFIRMATION, reservation.Restaurant, reservation.When.ToLongDateString(), reservation.When.ToLongTimeString());
            await context.PostAsync(text);

            // end the conversation (this will reset the dialog stack and clear all convesation state)
            context.EndConversation(EndOfConversationCodes.CompletedSuccessfully);
        }
Ejemplo n.º 25
0
        private async Task printQuitMessage(IDialogContext context)
        {
            try
            {
                await context.PostAsync("It was nice talking to you. Thanks for using Hungry Belly !");

                context.EndConversation("");
            }
            catch (Exception e)
            {
                await context.PostAsync("Argh something went wrong with quitting me! :( Sorry about that.");
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Completion dialog for Donation
        /// </summary>
        /// <param name="context"></param>
        /// <param name="response"></param>
        /// <returns></returns>
        public virtual async Task ChildDialogComplete(IDialogContext context, IAwaitable <object> response)
        {
            var message     = context.MakeMessage();
            var count       = donationFirstDialog.donationUrl.Length - 29;
            var donationId  = donationFirstDialog.donationUrl.Substring(29, count);
            var donationUrl = _restApiUtil.ServerUrl + "" + donationFirstDialog.donationUrl;
            var attachment  = ThankYouCard(donationUrl, donationId);

            message.Attachments.Add(attachment);
            await context.PostAsync(message);

            context.EndConversation(EndOfConversationCodes.CompletedSuccessfully);
        }
Ejemplo n.º 27
0
        public async Task CourseLastStep(IDialogContext context, IAwaitable <BooleanChoice> activity)
        {
            try
            {
                var response = await activity;
                if (response.Equals(BooleanChoice.Yes))
                {
                    context.Done(this);
                }
                else
                {
                    await context.PostAsync("Thanks for your valuable time. I would be glad to help you if you might be interested for enrollment in future !!!");

                    context.EndConversation(EndOfConversationCodes.CompletedSuccessfully);
                }
            }
            catch
            {
                await context.PostAsync("Thanks for your valuable time !!!");

                context.EndConversation(EndOfConversationCodes.CompletedSuccessfully);
            }
        }
Ejemplo n.º 28
0
        private async Task OnCategoryOptionSelected(IDialogContext context, IAwaitable <string> result)
        {
            try
            {
                string   fullResult = await result;
                string[] option     = fullResult.Split(null);
                string   category   = option[0];
                string   preamble;

                switch (category)
                {
                case ServiceCategory.Vision:
                    preamble = ServiceDetails.VisionDescription + "\n";
                    break;

                case ServiceCategory.Speech:
                    preamble = ServiceDetails.SpeechDescription + "\n";
                    break;

                case ServiceCategory.Language:
                    preamble = ServiceDetails.LanguageDescription + "\n";
                    break;

                case ServiceCategory.Knowledge:
                    preamble = ServiceDetails.KnowledgeDescription + "\n";
                    break;

                case ServiceCategory.Search:
                    preamble = ServiceDetails.SearchDescription + "\n";
                    break;

                default:
                    preamble = ServiceDetails.DefaultDescription;
                    await context.PostAsync(preamble);

                    context.Done <object>(null);
                    return;
                }

                var model = ProductModel.GetContextData(context);
                model.Category = category;
                ProductModel.SetContextData(context, model);

                context.Done(preamble);
            }
            catch (TooManyAttemptsException ex)
            {
                context.EndConversation($"Ooops! Too many attemps :(. But don't worry, I'm handling that exception and you can try again!");
            }
        }
Ejemplo n.º 29
0
        private async Task OnUserChoiceMade(IDialogContext context, IAwaitable <string> result)
        {
            var choice = await result;

            if (choice.Contains("Upload"))
            {
                await context.PostAsync("Please select an image to upload.");

                context.Wait(GetImageAsync);
            }
            else if (choice.Contains("View"))
            {
                try
                {
                    //You don't need to pass credential when deploying to Compute Engine as it picks up the credential automatically.
                    //Your code will look like this - var client = StorageClient.Create();
                    var    credential = GoogleCredential.FromFile(@"PATHTOKEY.json");
                    var    client     = StorageClient.Create(credential);
                    Bucket bucket     = null;
                    bucket = await SetUpGCP(client, bucket);

                    bool             noImagePresent = true;
                    IMessageActivity message        = context.MakeMessage();

                    foreach (var obj in client.ListObjects(bucket.Name))
                    {
                        noImagePresent = false;
                        message.Attachments.Add(new Attachment()
                        {
                            ContentUrl  = obj.MediaLink,
                            ContentType = obj.ContentType
                        });
                    }

                    await context.PostAsync(message);

                    if (noImagePresent)
                    {
                        message.Text = "Sorry. No images uploaded yet.";
                        await context.PostAsync(message);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                context.EndConversation("See you soon");
            }
        }
Ejemplo n.º 30
0
        public async Task CarStart(IDialogContext context, LuisResult result)
        {
            await IoTHelper.SendAsync("s50");

            await context.PostAsync("3");

            await context.PostAsync("2");

            await context.PostAsync("1");

            await context.PostAsync("GO !!!!!!");

            context.EndConversation("Conversation Ended");
        }