public async Task <Result> SendUserNotification(string userId, string message) { var messaging = new AccessTokenClient(AccessTokenClient.ApiDomainBaseAddress); var token = (await messaging.Send(configuration.AldoClientId, configuration.AldoClientSecret)).Token; var deployEvent = new MessageReminder( new MessageReminderState(MessageReminderStatus.Unread, MessageReminderFreshness.New), new MessageReminderGroup(message, 1, MessageReminderUrgency.Urgent)); var userReq = new UserEventRequest(userId, deployEvent) { ReferenceId = Guid.NewGuid().ToString(), ExpiryTime = DateTimeExtensions.ItaNow().AddMinutes(6), TimeStamp = DateTimeExtensions.ItaNow() }; var client = new ProactiveEventsClient(ProactiveEventsClient.EuropeEndpoint, token, true); var result = await client.Send(userReq); if (result.IsSuccessStatusCode) { return(Result.Ok()); } var errorContent = await result.Content.ReadAsStringAsync(); var error = $"{result.ReasonPhrase}\n\r{errorContent}"; return(Result.Fail(error)); }
private static async Task <string> GetOAuthToken() { var clientId = Environment.GetEnvironmentVariable("clientid"); var clientSecret = Environment.GetEnvironmentVariable("clientsecret"); if (string.IsNullOrWhiteSpace(clientId) || string.IsNullOrWhiteSpace(clientSecret)) { throw new InvalidOperationException("invalid oauth creds"); } var client = new AccessTokenClient(AccessTokenClient.ApiDomainBaseAddress); var accessToken = await client.Send(clientId, clientSecret); return(accessToken.Token); }