コード例 #1
0
ファイル: RootDialog.cs プロジェクト: sky5005e/BotBol7
#pragma warning restore 1998

        /// <summary>
        /// Responds back to the sender with the message received or in case the message contains
        /// a specific keyword, will try to connect with a human (in 1:1 conversation).
        /// </summary>
        /// <param name="context"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        private async Task OnMessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            IMessageActivity messageActivity = await result;
            string           message         = messageActivity.Text;

            if (!string.IsNullOrEmpty(message))
            {
                if (message.ToLower().Contains(MessagesController.CommandRequestConnection))
                {
                    WebApiConfig.MessageRouterManager.RequestConnection((messageActivity as Activity));
                    context.Done(this);
                }
                else
                {
                    messageActivity = context.MakeMessage();
                    //messageActivity.Text = Respondsanswer(message);
                    var answers = new Repository.QuesAnsRepo().GetList(message);
                    if (answers.Count() > 1)
                    {
                        //var list = answers.Select(q => q.QuestionDesc).ToList();
                        //var form = new FormDialog<MyForm>(new MyForm(list), MyForm.BuildForm, FormOptions.PromptInStart);
                        //context.Call(form, Form_Callback);

                        var form = new FormDialog <QuestionTemplate>(new QuestionTemplate(message), QuestionTemplate.BuildPlaceForm, FormOptions.PromptInStart);
                        context.Call(form, QuestionTemplate_Callback);

                        await Task.CompletedTask;
                    }
                    else
                    {
                        if (answers != null && answers.Count > 0)
                        {
                            messageActivity.Text = $"{answers[0].AnswerDesc}";
                            if (!string.IsNullOrEmpty(answers[0].FilePath))
                            {
                                messageActivity.Attachments = new List <Attachment> {
                                    Utils.Utility.GetServerAttachment(answers[0].FilePath, answers[0].FileName)
                                };
                            }
                        }
                        else
                        {
                            messageActivity.Text = $"Sorry didn't understand. " +
                                                   //$"\n\rType \"{Commands.CommandKeyword} {Commands.CommandListOptions}\" to see all command options." +
                                                   $"\n\rType \"{MessagesController.CommandRequestConnection}\" to initiate conversation with human agent.";
                            messageActivity.Attachments = new List <Attachment> {
                                Utils.Utility.GetInternetAttachment()
                            };
                        }
                        //$"{ConversationText.EchoMessage}: {message}\n\rType \"{Commands.CommandKeyword} {Commands.CommandListOptions}\" to see all command options.\n\rType \"{MessagesController.CommandRequestConnection}\" to initiate conversation with human agent.";
                        await context.PostAsync(messageActivity);

                        //await Respond(context);
                        context.Done(this);
                    }
                }
            }
        }
コード例 #2
0
ファイル: RootDialog.cs プロジェクト: sky5005e/BotBol7
        private string Respondsanswer(string ques)
        {
            var answer = new Repository.QuesAnsRepo().GetList(ques);

            if (answer != null && answer.Count > 0)
            {
                //if (answer.Count == 1)
                return($"{answer[0].AnswerDesc}");
                //else
                //  return $", \n\rType \"{Commands.CommandKeyword} {Commands.CommandListOptions}\" to see all command options.\n\rType \"{MessagesController.CommandRequestConnection}\" to initiate conversation with human agent.";
            }
            else
            {
                return($"Sorry didn't understand. " +
                       //$"\n\rType \"{Commands.CommandKeyword} {Commands.CommandListOptions}\" to see all command options." +
                       $"\n\rType \"{MessagesController.CommandRequestConnection}\" to initiate conversation with human agent.");
            }
        }