示例#1
0
        public async Task <bool> RemindAsync(string tenant, ReminderMessage message)
        {
            await Task.Delay(0).ConfigureAwait(false);

            if (string.IsNullOrWhiteSpace(message.Contact.MobileNumbers))
            {
                return(false);
            }

            int alarm = message.Event.Alarm ?? 0;

            if (alarm == 0)
            {
                return(false);
            }

            string timezone = message.Contact.TimeZone.Or(message.Event.TimeZone);

            string template  = Configs.GetNotificationEmailTemplate(tenant);
            string eventDate = TimeZoneInfo.ConvertTime(DateTime.UtcNow.AddMinutes(alarm), TimeZoneInfo.FindSystemTimeZoneById(timezone)).Date.ToString("D");
            string startTime = TimeZoneInfo.ConvertTime(message.Event.StartsAt, TimeZoneInfo.FindSystemTimeZoneById(timezone)).ToString("t");
            string endTime   = TimeZoneInfo.ConvertTime(message.Event.EndsOn, TimeZoneInfo.FindSystemTimeZoneById(timezone)).ToString("t");

            template = template.Replace("{Name}", message.Event.Name);
            template = template.Replace("{StartTime}", startTime);
            template = template.Replace("{EndTime}", endTime);
            template = template.Replace("{Date}", eventDate);
            template = template.Replace("{Location}", message.Event.Location);
            template = template.Replace("{Note}", message.Event.Note);


            var processor = SmsProcessor.GetDefault(tenant);

            if (processor == null)
            {
                return(false);
            }

            var textMessage = new SmsQueue
            {
                AddedOn    = DateTimeOffset.UtcNow,
                SendOn     = DateTimeOffset.UtcNow,
                SendTo     = message.Contact.MobileNumbers,
                FromName   = processor.Config.FromName,
                FromNumber = processor.Config.FromNumber,
                Subject    = string.Format(I18N.CalendarNotificationEmailSubject, message.Event.Name, startTime),
                Message    = template
            };

            var manager = new SmsQueueManager(tenant, textMessage);
            await manager.AddAsync().ConfigureAwait(false);

            await manager.ProcessQueueAsync(processor).ConfigureAwait(false);

            return(true);
        }
示例#2
0
        public static async Task <bool> SendAsync(string tenant, SmsViewModel model, LoginView meta)
        {
            var processor = SmsProcessor.GetDefault(tenant);

            if (processor == null)
            {
                return(false);
            }

            foreach (var contactId in model.Contacts)
            {
                var contact = await DAL.Contacts.GetContactAsync(tenant, model.UserId, contactId).ConfigureAwait(false);

                if (string.IsNullOrWhiteSpace(contact?.MobileNumbers) || !contact.MobileNumbers.Split(',').Any())
                {
                    continue;
                }

                //Only select the first cell number
                string cellNumber = contact.MobileNumbers.Split(',').Select(x => x.Trim()).FirstOrDefault();

                if (string.IsNullOrWhiteSpace(cellNumber))
                {
                    continue;
                }

                string message = model.Message;
                message = MessageParser.ParseMessage(message, contact);

                var sms = new SmsQueue
                {
                    AddedOn    = DateTimeOffset.UtcNow,
                    SendOn     = DateTimeOffset.UtcNow,
                    SendTo     = cellNumber,
                    FromName   = processor.Config.FromName.Or(meta.OfficeName),
                    FromNumber = processor.Config.FromNumber.Or(meta.Phone),
                    Subject    = model.Subject,
                    Message    = message
                };

                await new SmsQueueManager(tenant, sms).AddAsync().ConfigureAwait(false);
            }

            var queue = new SmsQueueManager
            {
                Database = tenant
            };

            await queue.ProcessQueueAsync(processor).ConfigureAwait(false);

            return(true);
        }