Exemplo n.º 1
0
        public TicketSysNotification Create(TicketSysNotification ticketSysNotification)
        {
            // Duplicate check
            var validate = _notif.Find(x => x.JiraCaseKey == ticketSysNotification.JiraCaseKey && x.OneTimeNotifToken == ticketSysNotification.OneTimeNotifToken).FirstOrDefault();

            if (validate == null)
            {
                _notif.InsertOne(ticketSysNotification);
                return(ticketSysNotification);
            }
            else
            {
                // If already exist, update one time notif token
                validate.OneTimeNotifToken = ticketSysNotification.OneTimeNotifToken;
                validate.ModifiedOn        = DateTime.Now;

                Update(validate.Id, validate);
            }
            return(null);
        }
Exemplo n.º 2
0
 public void Remove(TicketSysNotification ticketSysNotification) =>
 _notif.DeleteOne(x => x.Id == ticketSysNotification.Id);
Exemplo n.º 3
0
 public void Update(string id, TicketSysNotification ticketSysNotification) =>
 _notif.ReplaceOne(x => x.Id == id, ticketSysNotification);
Exemplo n.º 4
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);
            }
        }