private async Task SendEventNotofication(ITurnContext turnContext, string eventMessage) { PasswordNotfications notifications = await _passwordNotificationsPropertyAccessor.GetAsync(turnContext, () => new PasswordNotfications()); PasswordEventNotification passwordEventNotification = JsonConvert.DeserializeObject <PasswordEventNotification>(eventMessage); PasswordNotfications.NotificationData eventUserData = notifications[passwordEventNotification.PasswordEvent.UserID]; await SendNotificationsAsync(turnContext.Adapter, AppId, eventUserData, passwordEventNotification); }
private async Task SendNotificationsAsync( BotAdapter adapter, string botId, PasswordNotfications.NotificationData notification, PasswordEventNotification passwordEventNotification, CancellationToken cancellationToken = default(CancellationToken) ) { await adapter.ContinueConversationAsync(botId, notification.Conversation, CreateCallback(notification, passwordEventNotification), cancellationToken); }
// Creates the turn logic to use for the proactive message. private BotCallbackHandler CreateCallback(PasswordNotfications.NotificationData notification, PasswordEventNotification passwordEventNotification) { return(async(turnContext, token) => { // Get the job log from state, and retrieve the job. PasswordNotfications notifications = await _passwordNotificationsPropertyAccessor.GetAsync(turnContext, () => new PasswordNotfications()); // Set the new property await _passwordNotificationsPropertyAccessor.SetAsync(turnContext, notifications); // Now save it into the JobState await _notificationState.SaveChangesAsync(turnContext); // Send the user a proactive confirmation message. await turnContext.SendActivityAsync($"Password for {notification.UserID} is about to expire on {passwordEventNotification.PasswordEvent.PasswordExpirationDate}."); }); }