Beispiel #1
0
        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result)
        {
            var activity = await result as Activity;
            var text     = activity?.Value as string ?? activity.Text;

            //English mother@$!, do you speak it!?
            var isSupportedLanguage = Regex.IsMatch(text, @"^[a-zA-Z0-9\s\32-\151]+$");

            if (!isSupportedLanguage)
            {
                var responses = new String[]
                {
                    "我不会说中文!Please only use English words. I am but a simple chat bot.",
                    "Whoa, trailblazer. Testing the limits of cognitive AI! Nice! Please only use English.",
                    "I'm sorry, I only speak English! Let's talk about dim sum.",
                    "我不懂! Try asking again in English please. Ask me about dim sum!"
                };

                await context.DispatchAsync(responses.RandomElementOrDefault());

                context.Wait(MessageReceivedAsync);
            }
            else
            {
                await context.Forward(new LuisQueryDialog(), ResumeAfter_LuisQuery, activity, CancellationToken.None);
            }
        }
Beispiel #2
0
        public async Task GreetingIntent(IDialogContext context, IAwaitable <IMessageActivity> item, LuisResult result)
        {
            var stickerMessage = context.MakeMessage();

            stickerMessage.Attachments.Add(new Attachment
            {
                ContentUrl  = "https://dimsum-connector.azurewebsites.net/imgs/hi-sticker.png",
                ContentType = "image/png",
                Name        = "hi-sticker.png"
            });
            await context.DispatchAsync(stickerMessage);

            var greetings = new string[]
            {
                "Hello! Let's talk dim sum.",
                "Hey! I'm here to help you find out more about delicious dim sum",
                "你好! Ni Hao! That's all the Chinese I know, though. Please talk to me in English! Ask me about dim sum.",
                "Yo! It's dim sum time."
            };

            await context.DispatchAsync(greetings.RandomElementOrDefault());

            context.Done(string.Empty);
        }
Beispiel #3
0
        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result)
        {
            var activity = await result as Activity;
            var q        = activity.Value as string ?? activity.Text;

            var qnaService = GetQnAService();
            var qnaResults = await Microsoft.Bot.Builder.CognitiveServices.QnAMaker.Extensions.QueryServiceAsync(GetQnAService(), q);

            var bestAnswer = qnaResults.Answers.FirstOrDefault(a => a.Score >= CONFIDENCE_THRESHOLD);

            if (bestAnswer != null)
            {
                var msg = context.MakeMessage();

                try
                {
                    var heroCard = JsonConvert.DeserializeObject <HeroCard>(bestAnswer.Answer);
                    msg.Attachments.Add(heroCard.ToAttachment());
                }catch (JsonSerializationException ex)
                {
                    //Couldn't deserialize answer...
                    msg.Text = bestAnswer.Answer;
                }

                //var heroCard = new HeroCard
                //{
                //    Title = "DIM SUM!",
                //    Subtitle = bestAnswer.Answer,
                //    Images = new CardImage[]
                //    {
                //        new CardImage("https://thumb1.shutterstock.com/display_pic_with_logo/3842924/390423109/stock-photo-shrimp-shumai-a-steamed-dish-to-enjoy-the-sweet-tenderness-of-dried-sakura-shrimp-390423109.jpg")
                //    }
                //};



                await context.DispatchAsync(msg);

                context.Done(true);
            }
            else
            {
                context.Done(false);
            }
        }
Beispiel #4
0
        private async Task ResumeAfter_QnADialog(IDialogContext context, IAwaitable <bool> result)
        {
            var success = await result;

            if (!success)
            {
                var failureMessages = new String[]
                {
                    "I'm sorry, I have no idea what you're talking about.",
                    "Alright, you stumped me. Please try something else!",
                    "What are you talking about?",
                    "Oh, I just don't understand!",
                    "我不懂!"
                };

                await context.DispatchAsync(failureMessages.RandomElementOrDefault());
            }

            context.Wait(MessageReceivedAsync);
        }
Beispiel #5
0
        public async Task AskLocationIntent(IDialogContext context, IAwaitable <IMessageActivity> item, LuisResult result)
        {
            await context.DispatchAsync("Jing Fong in Chinatown! It's the best one!");

            context.Done(string.Empty);
        }
Beispiel #6
0
        public async Task AskRecommendationIntent(IDialogContext context, IAwaitable <IMessageActivity> item, LuisResult result)
        {
            await context.DispatchAsync("Cha Shao Su and Liu Lian Su are a killer combo of savory and sweet. Try them! Ask me more about them.");

            context.Done(string.Empty);
        }