Beispiel #1
0
        public async Task NotifyAsync(string templateKey, string channelKey, Dictionary <string, object> contextObjectinfos, Dictionary <string, string> customParamReplacements, params string[] recipientUserIds)
        {
            //Queue messages per each recipient user.
            foreach (var recipientUserId in recipientUserIds)
            {
                var payload = new AlertNotificationRequestDto
                {
                    TemplateKey             = templateKey,
                    ChannelKey              = channelKey,
                    ContextObjectInfos      = contextObjectinfos,
                    CustomParamReplacements = customParamReplacements,
                    RecipientUserId         = recipientUserId
                };

                await _serviceBusService.SendMessageAsync(new ServiceBusMessageDto
                {
                    MessagePayload   = JsonConvert.SerializeObject(payload),
                    CustomProperties = new Dictionary <string, object>
                    {
                        { ServiceBusMessageProperties.GroupId, _requestContext.GroupId },
                        { ServiceBusMessageProperties.UserId, _requestContext.UserId ?? string.Empty }
                    }
                }, _queueNameInfo.AlertNotifyQueueName);
            }
        }
Beispiel #2
0
        public async Task DispatchAlertAsync(AlertNotificationRequestDto alertReq)
        {
            var recipientUser = await _systemDataContext.GetDocumentAsync <User>(alertReq.RecipientUserId);

            var groupId  = _requestContext.GroupId;
            var culture  = recipientUser.Culture;
            var timezone = recipientUser.TimeZone;

            var template = await GetTemplateWithFallbackAsync(alertReq.TemplateKey, groupId, culture, alertReq.ChannelKey);

            if (template == null)
            {
                throw new YawnMassageException("TEMPLATE_NOT_FOUND");
            }

            await MergeTemplateWithMasterTemplateAsync(template, groupId, culture);

            //Prepare template placeholder replacements.
            var templateValueReplacements = await GetTemplateValueReplacements(alertReq, groupId, culture, timezone, template);

            //Replace placeholder values.
            _alertContentParserService.ApplyPlaceholderReplacements(template, templateValueReplacements);

            //Send the alert.
            var alertSenderService = _alertSenderServiceFactory.GetAlertSenderService(alertReq.ChannelKey);
            await alertSenderService.SendAsync(template.Content, template.Subject, template.SenderId, recipientUser);
        }
Beispiel #3
0
        private async Task <Dictionary <string, string> > GetTemplateValueReplacements(AlertNotificationRequestDto alertReq, string groupId, string culture, string timezone, AlertTemplate template)
        {
            if (alertReq.ContextObjectInfos == null)
            {
                alertReq.ContextObjectInfos = new Dictionary <string, object>();
            }

            //Inject default system context for all alerts.
            alertReq.ContextObjectInfos.Add(AlertObjectContextTypes.System, null);

            var templateValueReplacements = await GetContextValueReplacementsAsync(template, alertReq.ContextObjectInfos, groupId, culture, timezone);

            if (alertReq.CustomParamReplacements != null)
            {
                foreach (var kv in alertReq.CustomParamReplacements)
                {
                    templateValueReplacements.Add(kv.Key, kv.Value);
                }
            }

            return(templateValueReplacements);
        }