Exemplo n.º 1
0
        public IActionResult GetCaseDetail()
        {
            Company c = new Company()
            {
                TicketSysUrl      = "http://58.185.112.2:8550",
                TicketSysId       = "*****@*****.**",
                TicketSysPassword = Utility.ParseEInfo("DevS@b3r", _appSettings.General.SysInfo)
            };

            return(Ok(_caseMgmtService.GetCaseStatusAsync(c, "124", "ZZTST-1").Result));
        }
Exemplo n.º 2
0
        private async Task ValidateQnA(ConversationData conversation, string answer)
        {
            switch (conversation.LastQuestionAsked)
            {
            case (int)Question.CompanyName:
                // Validate message (reported issue) e.g. min length
                if (!string.IsNullOrEmpty(answer))
                {
                    // Search company from Jira (Get company code)
                    var clientResultList = await _caseMgmtService.GetClientCompanies(_company, answer);

                    // Search clients databases
                    // var clientList = _clientService.Get();
                    // var clientResult = clientList.Where(x => x.ClientCompanyName.ToLower() == answer.ToLower()).FirstOrDefault();

                    if (clientResultList.Count == 1)
                    {
                        var clientResult = clientResultList.FirstOrDefault();

                        if (clientResult.ClientCompanyName.ToLower().Equals(answer.ToLower()))
                        {
                            // Check client company exist, if yes update, else insert.
                            var createdClientCompany = _clientService.Create(clientResult);

                            //generate OTP and send to ticketsys user company's email
                            Random generator        = new Random();
                            var    verificationCode = generator.Next(0, 9999).ToString("D4");
                            // Add user
                            TicketSysUser user = new TicketSysUser {
                                UserFbId        = _senderInfo.id,
                                ClientCompanyId = createdClientCompany.Id,
                                CompanyId       = _company.Id, UserNickname = $"{_senderInfo.last_name} {_senderInfo.first_name}", Active = false, VerificationCode = verificationCode
                            };

                            _jiraUserMgmtService.Create(user);


                            conversation.Answered       = true;
                            conversation.AnswerFreeText = createdClientCompany.Id.ToString();
                            conversation.CreatedOn      = DateTime.Now;
                            _conversationService.UpsertActiveConversation($"{_senderInfo.senderConversationId}~{_company.FbPageId}", conversation);

                            // Ask for verification code
                            var testOTP = string.Empty;
                            if (answer == "ZTEST COMPANY")
                            {
                                testOTP = verificationCode;
                            }

                            await ConstructAndSendMessage(ConstructType.RequestVerificationCode, messageInfo : testOTP);

                            break;
                        }
                    }
                    conversation.CreatedOn = DateTime.Now;
                    _conversationService.UpsertActiveConversation($"{_senderInfo.senderConversationId}~{_company.FbPageId}", conversation);

                    var comNotFoundMsg = JObject.FromObject(new
                    {
                        recipient = new { id = _senderInfo.senderConversationId },
                        message   = new { text = $"I'm sorry :( , we can't find your company in our system. Please enter the correct name or you may also contact {_company.contactEmail} for the company name." }
                    });

                    // Invalid input / no company found, please try again
                    await ConstructAndSendMessage(ConstructType.Retry, null, comNotFoundMsg);
                }
                else
                {
                    conversation.CreatedOn = DateTime.Now;
                    _conversationService.UpsertActiveConversation($"{_senderInfo.senderConversationId}~{_company.FbPageId}", conversation);

                    // Invalid input / no company found, please try again
                    await ConstructAndSendMessage(ConstructType.Retry);
                }
                break;

            case (int)Question.VerificationCode:
                // Validate message (reported issue) e.g. min length
                if (!string.IsNullOrEmpty(answer))
                {
                    // Check previous conversation, get ClientCompanyGuid
                    List <ConversationData> qaConv = _conversationService.GetConversationList($"{_senderInfo.senderConversationId}~{_company.FbPageId}");
                    if (qaConv != null)
                    {
                        ConversationData verifyConv = qaConv.Where(x => x.LastQuestionAsked == (int)Question.CompanyName).FirstOrDefault();

                        // Check verification code
                        var TicketSysUser = _jiraUserMgmtService.Get(_senderInfo.id);

                        if (TicketSysUser.VerificationCode == answer)
                        {
                            // Check & Update ClientCompany to true
                            if (!TicketSysUser.Active)
                            {
                                TicketSysUser.Active = true;
                                _jiraUserMgmtService.Update(TicketSysUser.Id, TicketSysUser);
                            }


                            // Begin create ticket
                            await ConstructAndSendMessage(ConstructType.CreateTicket);
                        }
                        else
                        {
                            // Incorrect verification code. Try again or end conversation
                            conversation.CreatedOn = DateTime.Now;
                            _conversationService.UpsertActiveConversation($"{_senderInfo.senderConversationId}~{_company.FbPageId}", conversation);

                            var jObj = JObject.FromObject(new
                            {
                                recipient = new { id = _senderInfo.senderConversationId },
                                message   = new { text = $"Sorry, I didn't quite catch that. It seems like invalid option/answer." }
                            });

                            // Invalid input / no company found, please try again
                            await ConstructAndSendMessage(ConstructType.Retry, additionalMessage : jObj);
                        }
                    }
                    else
                    {
                        conversation.CreatedOn = DateTime.Now;
                        _conversationService.UpsertActiveConversation($"{_senderInfo.senderConversationId}~{_company.FbPageId}", conversation);

                        // Invalid input / no company found, please try again
                        await ConstructAndSendMessage(ConstructType.Retry);
                    }
                }
                else
                {
                    await ConstructAndSendMessage(ConstructType.NotImplemented);
                }
                break;

            case (int)Question.IssueApplicationName:
                // Validate message (reported issue) e.g. min length
                if (!string.IsNullOrEmpty(answer))
                {
                    conversation.Answered       = true;
                    conversation.AnswerFreeText = answer;
                    conversation.CreatedOn      = DateTime.Now;
                    _conversationService.UpsertActiveConversation($"{_senderInfo.senderConversationId}~{_company.FbPageId}", conversation);

                    // Ask for description
                    await ConstructAndSendMessage(ConstructType.TicketDescription);
                }
                else
                {
                    conversation.CreatedOn = DateTime.Now;
                    _conversationService.UpsertActiveConversation($"{_senderInfo.senderConversationId}~{_company.FbPageId}", conversation);

                    // Invalid input / no company found, please try again
                    await ConstructAndSendMessage(ConstructType.Retry);
                }
                break;

            case (int)Question.IssueDescription:
                // Validate message (reported issue) e.g. min length
                if (!string.IsNullOrEmpty(answer))
                {
                    conversation.Answered       = true;
                    conversation.AnswerFreeText = answer;
                    conversation.CreatedOn      = DateTime.Now;
                    _conversationService.UpsertActiveConversation($"{_senderInfo.senderConversationId}~{_company.FbPageId}", conversation);

                    var conversationList = _conversationService.GetConversationList($"{_senderInfo.senderConversationId}~{_company.FbPageId}");

                    string jiraSummary     = conversationList.FirstOrDefault(x => x.LastQuestionAsked == (int)Question.IssueApplicationName).AnswerFreeText;
                    string jiraDescription = conversationList.FirstOrDefault(x => x.LastQuestionAsked == (int)Question.IssueDescription).AnswerFreeText;

                    // Show case summary & ask for creation confirmation
                    await ConstructAndSendMessage(ConstructType.TicketCreationConfirmation, new CaseDetail { Subject = $"Issue in {jiraSummary}", Detail = jiraDescription });
                }
                else
                {
                    conversation.CreatedOn = DateTime.Now;
                    _conversationService.UpsertActiveConversation($"{_senderInfo.senderConversationId}~{_company.FbPageId}", conversation);

                    // Invalid input / no company found, please try again
                    await ConstructAndSendMessage(ConstructType.Retry);
                }
                break;

            case (int)Question.TicketCode:
                // Validate message (reported issue) e.g. min length
                if (!string.IsNullOrEmpty(answer))
                {
                    // Jira integration here
                    // Search ticket status

                    CaseDetail caseDetail = null;
                    try
                    {
                        List <TicketSysUser> ticketSysUserList = _jiraUserMgmtService.Get();
                        var ticketSysUser = ticketSysUserList.Where(x => x.UserFbId == _senderInfo.senderConversationId).FirstOrDefault();

                        var clientCompany = _clientService.GetById(ticketSysUser.ClientCompanyId);

                        caseDetail = await _caseMgmtService.GetCaseStatusAsync(_company, clientCompany.TicketSysCompanyCode, answer);
                    }
                    catch { }

                    if (caseDetail != null)
                    {
                        conversation.Answered       = true;
                        conversation.AnswerFreeText = answer;
                        conversation.CreatedOn      = DateTime.Now;
                        _conversationService.UpsertActiveConversation($"{_senderInfo.senderConversationId}~{_company.FbPageId}", conversation);

                        await ConstructAndSendMessage(ConstructType.TicketFound, caseDetail);
                    }
                    else
                    {
                        conversation.CreatedOn = DateTime.Now;
                        _conversationService.UpsertActiveConversation($"{_senderInfo.senderConversationId}~{_company.FbPageId}", conversation);

                        var reply = JObject.FromObject(new
                        {
                            recipient = new { id = _senderInfo.senderConversationId },
                            message   = new { text = $"Looks like you have entered a wrong ticket code 😟" }
                        });
                        // Invalid input / no company found, please try again
                        await ConstructAndSendMessage(ConstructType.Retry, additionalMessage : reply);
                    }
                }
                else
                {
                    conversation.CreatedOn = DateTime.Now;
                    _conversationService.UpsertActiveConversation($"{_senderInfo.senderConversationId}~{_company.FbPageId}", conversation);

                    // Invalid input / no company found, please try again
                    await ConstructAndSendMessage(ConstructType.Retry);
                }
                break;

            default:
                break;
            }
        }
Exemplo n.º 3
0
        public async Task UserOptinCaseNoification(Messaging message, Company company)
        {
            try
            {
                _company = company;

                var jiraCaseKey       = message.optin.payload.Replace(FacebookCustomPayload.CASE_GET_NOTIFIED, string.Empty);
                var oneTimeNotifToken = message.optin.one_time_notif_token;

                var user = _jiraUserMgmtService.GetUser(message.sender.id, _company.Id);
                var ticketUserCompany = _clientCompanyService.GetById(user.ClientCompanyId);

                // Get current ticket status
                CaseDetail caseDetail = null;
                try
                {
                    caseDetail = await _jiraCaseMgmtService.GetCaseStatusAsync(company, ticketUserCompany.TicketSysCompanyCode, jiraCaseKey);
                }
                catch { }

                // Jira no result

                TicketSysNotification ticketSysNotification = new TicketSysNotification
                {
                    TicketSysUserId   = user.Id,
                    OneTimeNotifToken = oneTimeNotifToken,
                    JiraCaseKey       = jiraCaseKey,
                    JiraCaseStatus    = caseDetail != null ? caseDetail.Status : null,
                };

                _userCaseNotifService.Create(ticketSysNotification);

                List <JObject> messageList = new List <JObject>();

                messageList.Add(JObject.FromObject(new
                {
                    recipient = new { id = message.sender.id },
                    message   = new { text = $"All set! We'll send you a notification when there is an update! 👍" }
                }));
                messageList.Add(JObject.FromObject(new
                {
                    recipient = new { id = message.sender.id },
                    message   = new { text = $"Thank you for using TicketBOT! Have a nice day! :)" }
                }));

                foreach (var msg in messageList)
                {
                    await _fbApiClientService.PostMessageAsync(Utility.ParseDInfo(_company.FbPageToken, _applicationSettings.General.SysInfo), msg);
                }
            }
            catch (Exception ex)
            {
                var errMsg = JObject.FromObject(new
                {
                    recipient = new { id = message.sender.id },
                    message   = new { text = $"DEBUG --> Error. Check exception" }
                });
                await _fbApiClientService.PostMessageAsync(Utility.ParseDInfo(_company.FbPageToken, _applicationSettings.General.SysInfo), errMsg);

                LoggingHelper.LogError(ex, _logger);
            }
        }