Пример #1
0
        private void LattePandaCommunication_onLatteDataReceived(object sender, LatteDataReceivedEventArgs e)
        {
            dynamic syncData = null;
            string  mess     = e.Message;

            if (string.IsNullOrWhiteSpace(mess) || mess == "\n")
            {
                return;
            }
            Debug.WriteLine(mess);
            if (mess.Contains("SendAgain"))
            {
                GlobalFlowControl.SendToBaseAgain();
                return;
            }
            try
            {
                syncData = JsonConvert.DeserializeObject <SynchronisationData>(mess);
            }
            catch
            {
                Debug.WriteLine("Error! Requesting to receive again");
                GlobalFlowControl.SendToBase("SendAgain");
                return;
            }
        }
Пример #2
0
        public void InterpretMessage(string recMsg)
        {
            if (recMsg == null)
            {
                return;
            }

            //System.Windows.Forms.MessageBox.Show(recMsg);
            string[] msg = recMsg.Split(new[] { '/' }, 2);

            //msg[0] contains the header of the recMsg
            switch (msg[0])
            {
            case "StartCall":
                StartCall();
                break;

            case "Announcement":
                Annoucement(msg[1]);
                break;

            case "Speech":
            case "Text":
                InterpretText(msg[1]);
                break;

            case "GuidedTour":
                StartGuidedTour(msg[1]);
                GlobalFlowControl.SendToBase(msg[0], msg[1]);
                break;

            case "Navigation":
                BaseHelper.GoUntilReachedGoalOrCanceled(msg[1]);
                break;

            case "Gesture":
                break;

            case "BaseMovement":

                BaseHelper.DoBaseMovements(msg[1]);

                //GlobalFlowControl.SendToBase(msg[0], msg[1]);
                break;

            case "EndCall":
                GlobalFlowControl.TelepresenceMode = false;
                BaseHelper.Stop();
                //GlobalFlowControl.SendToBase("Telepresence", "quit");
                break;
            }
        }
Пример #3
0
 public static void SpeakInBody(string msg)
 {
     GlobalFlowControl.SendToBase("Speech", msg);
 }
Пример #4
0
        private static async Task HandleBotResponse(IEnumerable <Activity> activities, string userQuery)
        {
            foreach (Activity activity in activities)
            {
                if (activity.Text != null)
                {
                    string[] allAnswers = activity.Text.Split('|');

                    Random rand = new Random();

                    string randomAns = allAnswers[rand.Next(allAnswers.Length)];

                    AnswerTemplate answer = new AnswerTemplate();
                    answer.SplitMessage(randomAns);

                    ConversationGlobalFlow.AskAgain = false;
                    //answer.MessageToSpeak = "ask again"
                    Debug.WriteLine("Reply: " + answer.MessageToSpeak);

                    ExcelHelper.AddData(userQuery, answer.MessageToSpeak);
                    if (GlobalFlowControl.moduleActivated == false)
                    {
                        return;
                    }
                    if (answer.MessageToSpeak.ToLower().Contains("ask again"))
                    {
                        if (GlobalFlowControl.moduleActivated == false ||
                            GlobalFlowControl.ChatbotInterrupted == true)
                        {
                            return;
                        }

                        /*ConversationGlobalFlow.AskAgain = true;
                         * askAgainCount++;
                         * if (askAgainCount == 2)
                         * {
                         *  GlobalFlowControl.SendToBase("ChatBot", "StopTalking");
                         *  askAgainCount = 0;
                         *  ConversationGlobalFlow.AskAgain = false;
                         *  return;
                         * } */
                        //GlobalFlowControl.SendToBase("ChatBot", "IsTalking");
                        //SpeechGeneration.SpeakSync("Sorry. I don't understand!");
                        answer.MessageToSpeak = "Sorry. I don't understand";
                        //return;
                    }
                    else
                    {
                        askAgainCount = 0;
                    }


                    if (GlobalFlowControl.moduleActivated == false)
                    {
                        return;
                    }
                    if (answer.PicturePath != null)
                    {
                        if (answer.AutoNavLocation != null)
                        {
                            answer.PicturePath = @"locations\" + answer.PicturePath;
                        }
                        else
                        {
                            answer.PicturePath = @"qna\" + answer.PicturePath;
                        }

                        GlobalFlowControl.SendToBase("DisplayMedia", answer.PicturePath);
                        if (answer.DisplayMediaDuration == 0)
                        {
                            answer.DisplayMediaDuration += 2;
                        }
                    }

                    try
                    {
                        if (GlobalFlowControl.moduleActivated == false)
                        {
                            return;
                        }
                        GlobalFlowControl.SendToBase("ChatBot", "IsTalking");
                        SaySync(answer.MessageToSpeak);

                        if (answer.VideoPath != null)
                        {
                            GlobalFlowControl.SendToBase("VideoPath", answer.VideoPath);
                        }

                        if (answer.DisplayMediaDuration > 0)
                        {
                            Thread.Sleep(1000 * answer.DisplayMediaDuration);
                        }

                        if (answer.AutoNavLocation != null)
                        {
                            SaySync("Do you want me to lead you there?");
                            SayAsync("Yes or No?");
                            GlobalFlowControl.SendToBase("DisplayMedia", GlobalData.ListeningModeImg);
                            string reply = await SpeechRecognition.RecognizeQuery(3000).ConfigureAwait(false);

                            if (reply != null)
                            {
                                reply = reply.ToLower();
                                if (reply.Contains("yes") ||
                                    reply.Contains("yeah") ||
                                    reply.Contains("yup") ||
                                    reply.Contains("ok"))
                                {
                                    SaySync("OK! Follow me");
                                    GlobalFlowControl.IsNavigationInChatBot = true;
                                    GlobalFlowControl.IsReachedGoal         = false;
                                    GlobalFlowControl.IsCancelledNavigation = false;

                                    var data = new SynchronisationData
                                    {
                                        Navigation = answer.AutoNavLocation,
                                        ChatBot    = "NavigationOn"
                                    };

                                    GlobalFlowControl.SendToBase(data);

                                    /*while (!GlobalFlowControl.IsReachedGoal
                                     *  && !GlobalFlowControl.IsCancelledNavigation) ;
                                     * Thread.Sleep(500);
                                     * GlobalFlowControl.SendToBase("Navigation", "Stop");
                                     * if (GlobalFlowControl.IsCancelledNavigation) return;
                                     */
                                    return;
                                }

                                SaySync("Thank you, have a nice day");
                            }
                        }
                    }
                    catch
                    {
                        if (GlobalFlowControl.ChatbotInterrupted)
                        {
                            continue;
                        }
                    }
                    GlobalFlowControl.SendToBase("ChatBot", "StopTalking");
                }
            }
        }
Пример #5
0
 private static void DisplayDefaultBackgroundImage()
 {
     GlobalFlowControl.SendToBase("DisplayMedia", GlobalData.ChatBotActivationImg);
 }
Пример #6
0
        private static async Task Conversation()
        {
            while (GlobalFlowControl.moduleActivated)
            {
                GlobalFlowControl.ChatbotInterrupted = false;
                if (timer.Enabled == false && !GlobalFlowControl.IsRoving &&
                    !GlobalFlowControl.AskByPressingButton)
                {
                    CheckIdle();
                }
                string userQuery = null;

                userQuery = await SpeechRecognition.Recognize().ConfigureAwait(false);

                //System.Windows.Forms.MessageBox.Show(userQuery);

                if (GlobalFlowControl.ChatbotInterrupted)
                {
                    continue;
                }

                if (GlobalFlowControl.moduleActivated == false)
                {
                    break;
                }

                if (userQuery != null)
                {
                    if (GlobalFlowControl.ChatbotInterrupted)
                    {
                        continue;
                    }
                    if (GlobalFlowControl.moduleActivated == false)
                    {
                        break;
                    }
                    await directLineClient.PostQuestionToBotAsync(userQuery).ConfigureAwait(false);

                    IEnumerable <Activity> activities = await directLineClient.ReadBotMessagesAsyncDriver().ConfigureAwait(false);

                    if (GlobalFlowControl.ChatbotInterrupted)
                    {
                        continue;
                    }
                    if (GlobalFlowControl.moduleActivated == false)
                    {
                        break;
                    }

                    await HandleBotResponse(activities, userQuery).ConfigureAwait(false);

                    if (GlobalFlowControl.ChatbotInterrupted)
                    {
                        continue;
                    }
                    if (GlobalFlowControl.moduleActivated == false)
                    {
                        break;
                    }
                }
                else
                {
                    ConversationGlobalFlow.AskAgain = false;
                }
            }

            directLineClient.EndConversion();
            GlobalFlowControl.moduleActivated = false;
            timer.Stop();

            //System.Windows.Forms.MessageBox.Show("Chatbot end" + GlobalFlowControl.ChatBotDisabledByBody);
            if (GlobalFlowControl.TelepresenceMode == false &&
                GlobalFlowControl.ChatBotDisabledByBody == false)
            {
                GlobalFlowControl.SendToBase("ChatBot", "quit");
            }

            GlobalFlowControl.ChatBotDisabledByBody = false;
            //System.Windows.Forms.MessageBox.Show("Chatbot end 2" + GlobalFlowControl.ChatBotDisabledByBody);
        }