Beispiel #1
0
        private async Task UserUnsubscribeNotification()
        {
            // Clear all notification queue in db
            var jiraUser = _jiraUserMgmtService.Get(_senderInfo.senderConversationId);

            List <TicketSysNotification> notifList = _tickSysNotifService.Get();

            notifList = notifList.Where(x => x.TicketSysUserId == jiraUser.Id).ToList();
            foreach (var notif in notifList)
            {
                _tickSysNotifService.Remove(notif);
            }

            var notifUnsubSuccess = JObject.FromObject(new
            {
                recipient = new { id = _senderInfo.senderConversationId },
                message   = new { text = $"Successfully unsubscribe notification." }
            });

            // Send ending
            await ConstructAndSendMessage(ConstructType.Ending, null, notifUnsubSuccess);
        }
Beispiel #2
0
        public async Task BlastJiraStatusUpdateNotification()
        {
            try
            {
                List <TicketSysNotification> pendingStatusUpdateNotifList = _userCaseNotifService.Get();

                foreach (var pending in pendingStatusUpdateNotifList)
                {
                    var ticketUser        = _jiraUserMgmtService.GetById(pending.TicketSysUserId);
                    var ticketUserCompany = _clientCompanyService.GetById(ticketUser.ClientCompanyId);
                    _company = _companyService.GetById(ticketUser.CompanyId);

                    CaseDetail caseDetail = null;
                    try
                    {
                        caseDetail = await _jiraCaseMgmtService.GetCaseStatusAsync(_company, ticketUserCompany.TicketSysCompanyCode, pending.JiraCaseKey);
                    }
                    catch { }

                    // Jira no result
                    if (caseDetail == null)
                    {
                        continue;
                    }

                    // If Jira status remain the same / no updates
                    var pendingStatus = pending.JiraCaseStatus ?? "";
                    if (caseDetail.Status.Trim().ToLower().Equals(pendingStatus.Trim().ToLower()))
                    {
                        continue;
                    }

                    // Prepare send notification
                    List <JObject> messageList = new List <JObject>();
                    messageList.Add(JObject.FromObject(new
                    {
                        recipient = new { one_time_notif_token = pending.OneTimeNotifToken },
                        message   = new { text = $"New Updates with Case: {caseDetail.CaseKey} \n\nStatus changed to: {caseDetail.Status} \n\nCase Subject: {caseDetail.Subject} \n\nClick the link below for more. \n{caseDetail.WebURL}" }
                    }));

                    // Delete entry from database
                    _userCaseNotifService.Remove(pending);

                    // If case status not completed, then ask whether want to subscribe for next update or not
                    if (caseDetail.Status != JiraServiceDeskStatus.Declined || caseDetail.Status != JiraServiceDeskStatus.Completed)
                    {
                        messageList.Add(JObject.FromObject(new
                        {
                            recipient = new { id = ticketUser.UserFbId },
                            message   = new
                            {
                                attachment = new
                                {
                                    type    = "template",
                                    payload = new
                                    {
                                        template_type = "one_time_notif_req",
                                        title         = $"Do you want to get notified with {pending.JiraCaseKey} updates?",
                                        payload       = string.Format(FacebookCustomPayload.CASE_GET_NOTIFIED_PAYLOAD, pending.JiraCaseKey)
                                    }
                                }
                            }
                        }));
                    }

                    foreach (var msg in messageList)
                    {
                        await _fbApiClientService.PostMessageAsync(Utility.ParseDInfo(_company.FbPageToken, _applicationSettings.General.SysInfo), msg);
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, _logger);
                throw;
            }
        }