private async Task <string> InstallButlerForInstance(StoredReminder reminder, ReminderInstance instance, Event e) { return(await butler.InstallAsync(new WebhookRequest() { Data = new ReminderProcessRequest() { InstanceId = instance.Id, ReminderId = reminder.Id, Hash = instance.Hash }, Url = options.ProcessReminderUri, When = e.Start.AddMinutes(-reminder.Minutes).UtcDateTime })); }
private async Task NotifyOrInstall(string userId, FocusItemWithExternalData item) { var timeToDeparture = item.IndicateTime - DateTimeOffset.Now; if (timeToDeparture < FocusConstants.NotifyTime.Add(FocusConstants.ButlerInaccuracy)) { var notifySemaphore = _notifySempahores.GetOrAdd(userId, s => new SemaphoreSlim(1)); await notifySemaphore.WaitAsync(); try { if (!await _focusStore.FocusItemNotifiedAsync(item.Id)) { try { await _digitPushServiceClient[userId].Push.Create(new DigitPushService.Models.PushRequest() { ChannelOptions = new Dictionary <string, string>() { { "digit.notify", null } }, Payload = JsonConvert.SerializeObject(new { notification = new { tag = item.Id, title = item.CalendarEvent == null ? "Losgehen" : $"Losgehen zu {item.CalendarEvent.Subject}", body = NotificationBody(item) } }) }); } catch (Exception e) { await _logger.LogForFocusItem(userId, item.Id, $"Could notify user ({e.Message}).", logLevel : LogLevel.Error); } await _focusStore.SetFocusItemNotifiedAsync(item.Id); // always set notified for now to prevent massive notification spam } } finally { notifySemaphore.Release(); } } else { // plan the notification anyways, even if the location might be updated, in case no update is received (low phone battery for example) // it will be ignored if any of the conditions (user location, traffic, event start time) changed await _butler.InstallAsync(new WebhookRequest() { When = item.IndicateTime.Add(-FocusConstants.NotifyTime).UtcDateTime, Data = new NotifyUserRequest() { UserId = userId, FocusItemId = item.Id }, Url = options.NotifyUserCallbackUri }); } }
private async Task InstallButlerForReminderRenewal(ReminderRegistration registration) { await butler.InstallAsync(new WebhookRequest() { When = registration.Expires.AddMinutes(-4), Data = new RenewReminderRequest() { ReminderId = registration.Id }, Url = options.ReminderMaintainanceCallbackUri }); }
private async Task InstallButlerForExpiration(string configId, string feedId, DateTime expires) { var butlerTime = DateTime.Now.AddMilliseconds((expires - DateTime.Now).TotalMilliseconds * RenewNotificationOn); await butler.InstallAsync(new WebhookRequest() { Data = new NotificationMaintainanceRequest() { ConfigurationId = configId, FeedId = feedId }, Url = options.NotificationMaintainanceUri, When = butlerTime }); }