Esempio n. 1
0
        private static async Task DoKnowledgeGraphScenario(IDialogContext context, IMessageActivity message)
        {
            var incomingChanData = message.GetChannelData <CustomChannelDataRequest>();

            //We keep cookies between client and Bing, so follow up questions such as "where is he from?" are understood in the context
            //of the previous question
            List <KeyValuePair <string, string> > cookies;

            context.UserData.TryGetValue("Cookies", out cookies);

            //We also keep the entity. We are not doing anything wtih it right now, but it helps any custom logic that needs to know
            //the current topic we're discussing
            string currentEntity = null;

            context.UserData.TryGetValue("Entity", out currentEntity);

            var kbData = await KnowledgeGraphHelper.QueryAsync(message.Text, cookies, currentEntity);

            var response = context.MakeMessage();

            response.Text = kbData?.DisplayText;

            var chanData = new CustomChannelDataResponse {
                Knowledge = kbData
            };

            chanData.RobotFeedback.SpokenText = kbData?.SpokenText;
            chanData.RobotFeedback.SpokenSSML = kbData?.SpokenSSML;

            if (kbData.Success)
            {
                chanData.RobotFeedback.Emotion = new[] { Emotions.Confident };
            }
            else
            {
                chanData.RobotFeedback.Emotion = new[] { Emotions.Worried, Emotions.Questioning };
            }

            response.ChannelData = chanData;

            if (kbData.Cookies != null)
            {
                context.UserData.SetValue("Cookies", kbData.Cookies);
            }

            var entityToStore = kbData?.Entities?.FirstOrDefault()?.CurrentEntity;

            if (entityToStore != null)
            {
                context.UserData.SetValue("Entity", entityToStore);
            }
            else
            {
                // Otherwise don't change the target entity, user might want to ask a follow up question on same topic
            }

            await context.PostAsync(response);
        }
Esempio n. 2
0
        //The custom app running on the robot espects a specific kind of payload which includes not only what the robot is supposed to say, but
        //also facial expressions, facial movements, etc. This method is just a shortcut to build that payload before answering to the robot
        public static async Task <IMessageActivity> CreateResponse(IDialogContext context, IMessageActivity message, string[] emotions, string text)
        {
            var response = context.MakeMessage();

            response.Text = text;

            var chanData = new CustomChannelDataResponse
            {
                RobotFeedback = new RobotFeedback
                {
                    Emotion    = emotions,
                    SpokenText = text
                },
            };

            response.ChannelData = chanData;
            return(response);
        }