public async Task <IActionResult> PostIntegration(string appId, [FromBody] CreateIntegrationDto request) { var update = request.ToUpdate(); var app = await appStore.UpsertAsync(appId, update, HttpContext.RequestAborted); var response = IntegrationCreatedDto.FromDomainObject(app, update.Id); return(Ok(response)); }
public async Task Should_create_integration() { // STEP 1: Create integration var emailIntegrationRequest = new CreateIntegrationDto { Type = "SMTP", Properties = new Dictionary <string, string> { ["host"] = "localhost", ["fromEmail"] = "*****@*****.**", ["fromName"] = "Hello Notifo", ["port"] = "1025" }, Enabled = true }; var integration = await _.Client.Apps.PostIntegrationAsync(_.AppId, emailIntegrationRequest); Assert.True(integration.Integration.Enabled); }
public async Task Should_send_email(string kind) { var appName = Guid.NewGuid().ToString(); // STEP 0: Create app var createRequest = new UpsertAppDto { Name = appName }; var app_0 = await _.Client.Apps.PostAppAsync(createRequest); // STEP 1: Create email template. var emailTemplateRequest = new CreateChannelTemplateDto { Kind = kind }; await _.Client.EmailTemplates.PostTemplateAsync(app_0.Id, emailTemplateRequest); // STEP 2: Create integration var emailIntegrationRequest = new CreateIntegrationDto { Type = "SMTP", Properties = new Dictionary <string, string> { ["host"] = mailcatcher.SmtpHost, ["fromEmail"] = "*****@*****.**", ["fromName"] = "Hello Notifo", ["port"] = mailcatcher.SmtpPort.ToString(CultureInfo.InvariantCulture) }, Enabled = true }; await _.Client.Apps.PostIntegrationAsync(app_0.Id, emailIntegrationRequest); // STEP 3: Create user var userRequest = new UpsertUsersDto { Requests = new List <UpsertUserDto> { new UpsertUserDto { EmailAddress = "*****@*****.**" } } }; var users_0 = await _.Client.Users.PostUsersAsync(app_0.Id, userRequest); var user_0 = users_0.First(); // STEP 4: Send email var subjectId = Guid.NewGuid().ToString(); var publishRequest = new PublishManyDto { Requests = new List <PublishDto> { new PublishDto { Topic = $"users/{user_0.Id}", Preformatted = new NotificationFormattingDto { Subject = new LocalizedText { ["en"] = subjectId } }, Settings = new Dictionary <string, ChannelSettingDto> { [Providers.Email] = new ChannelSettingDto { Send = ChannelSend.Send } } } } }; await _.Client.Events.PostEventsAsync(app_0.Id, publishRequest); // Get email status using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30))) { while (!cts.IsCancellationRequested) { var messages = await mailcatcher.GetMessagesAsync(cts.Token); var message = messages.FirstOrDefault(x => x.Subject.Contains(appName, StringComparison.OrdinalIgnoreCase)); if (message != null) { var body = await mailcatcher.GetBodyAsync(message.Id, cts.Token); Assert.Contains(subjectId, body.Plain, StringComparison.OrdinalIgnoreCase); Assert.Contains(subjectId, body.Html, StringComparison.OrdinalIgnoreCase); return; } await Task.Delay(50); } } Assert.False(true, "Email not received."); }
public async Task Should_not_send_email_when_template_missing() { var appName = Guid.NewGuid().ToString(); // STEP 0: Create app var createRequest = new UpsertAppDto { Name = appName }; var app_0 = await _.Client.Apps.PostAppAsync(createRequest); // STEP 1: Create integration var emailIntegrationRequest = new CreateIntegrationDto { Type = "SMTP", Properties = new Dictionary <string, string> { ["host"] = mailcatcher.SmtpHost, ["fromEmail"] = "*****@*****.**", ["fromName"] = "Hello Notifo", ["port"] = mailcatcher.SmtpPort.ToString(CultureInfo.InvariantCulture) }, Enabled = true }; await _.Client.Apps.PostIntegrationAsync(app_0.Id, emailIntegrationRequest); // STEP 2: Create user var userRequest = new UpsertUsersDto { Requests = new List <UpsertUserDto> { new UpsertUserDto { EmailAddress = "*****@*****.**" } } }; var users_0 = await _.Client.Users.PostUsersAsync(app_0.Id, userRequest); var user_0 = users_0.First(); // STEP 3: Send email var subjectId = Guid.NewGuid().ToString(); var publishRequest = new PublishManyDto { Requests = new List <PublishDto> { new PublishDto { Topic = $"users/{user_0.Id}", Preformatted = new NotificationFormattingDto { Subject = new LocalizedText { ["en"] = subjectId } }, Settings = new Dictionary <string, ChannelSettingDto> { [Providers.Email] = new ChannelSettingDto { Send = ChannelSend.Send } } } } }; await _.Client.Events.PostEventsAsync(app_0.Id, publishRequest); var logs = await _.Client.Logs.WaitForLogEntriesAsync(app_0.Id, null, TimeSpan.FromSeconds(30)); Assert.Contains(logs, x => x.Message.Contains("Cannot find template", StringComparison.OrdinalIgnoreCase)); }
public async Task Should_send_webhook() { var appName = Guid.NewGuid().ToString(); // STEP 0: Create app var createRequest = new UpsertAppDto { Name = appName }; var app_0 = await _.Client.Apps.PostAppAsync(createRequest); // STEP 1: Start webhook session var(url, sessionId) = await webhookCatcher.CreateSessionAsync(); // STEP 2: Create integration var emailIntegrationRequest = new CreateIntegrationDto { Type = "Webhook", Properties = new Dictionary <string, string> { ["Url"] = url, ["SendAlways"] = "true", ["SendConfirm"] = "true" }, Enabled = true }; await _.Client.Apps.PostIntegrationAsync(app_0.Id, emailIntegrationRequest); // STEP 3: Create user var userRequest = new UpsertUsersDto { Requests = new List <UpsertUserDto> { new UpsertUserDto() } }; var users_0 = await _.Client.Users.PostUsersAsync(app_0.Id, userRequest); var user_0 = users_0.First(); // STEP 4: Send webhook var subjectId = Guid.NewGuid().ToString(); var publishRequest = new PublishManyDto { Requests = new List <PublishDto> { new PublishDto { Topic = $"users/{user_0.Id}", Preformatted = new NotificationFormattingDto { Subject = new LocalizedText { ["en"] = subjectId } }, Settings = new Dictionary <string, ChannelSettingDto> { [Providers.WebHook] = new ChannelSettingDto { Send = ChannelSend.Send } } } } }; await _.Client.Events.PostEventsAsync(app_0.Id, publishRequest); // Get webhook status var requests = await webhookCatcher.WaitForRequestsAsync(sessionId, TimeSpan.FromSeconds(30)); Assert.Contains(requests, x => x.Method == "POST" && x.Content.Contains(subjectId, StringComparison.OrdinalIgnoreCase)); }
public async Task Should_send_sms_with_template() { var appName = Guid.NewGuid().ToString(); // STEP 0: Create app var createRequest = new UpsertAppDto { Name = appName }; var app_0 = await _.Client.Apps.PostAppAsync(createRequest); // STEP 1: Create sms template. var smsTemplateRequest = new CreateChannelTemplateDto { }; var template_0 = await _.Client.SmsTemplates.PostTemplateAsync(app_0.Id, smsTemplateRequest); var smsTemplate = new SmsTemplateDto { Text = "<start>{{ notification.subject }}</end>" }; await _.Client.SmsTemplates.PutTemplateLanguageAsync(app_0.Id, template_0.Id, "en", smsTemplate); // STEP 2: Create integration var emailIntegrationRequest = new CreateIntegrationDto { Type = "MessageBird", Properties = new Dictionary <string, string> { ["accessKey"] = AccessKey, ["phoneNumber"] = PhoneNumber, ["phoneNumbers"] = string.Empty }, Enabled = true }; await _.Client.Apps.PostIntegrationAsync(app_0.Id, emailIntegrationRequest); // STEP 3: Create user var userRequest = new UpsertUsersDto { Requests = new List <UpsertUserDto> { new UpsertUserDto { PhoneNumber = PhoneNumber } } }; var users_0 = await _.Client.Users.PostUsersAsync(app_0.Id, userRequest); var user_0 = users_0.First(); // STEP 4: Send SMS var subjectId = Guid.NewGuid().ToString(); var publishRequest = new PublishManyDto { Requests = new List <PublishDto> { new PublishDto { Topic = $"users/{user_0.Id}", Preformatted = new NotificationFormattingDto { Subject = new LocalizedText { ["en"] = subjectId } }, Settings = new Dictionary <string, ChannelSettingDto> { [Providers.Sms] = new ChannelSettingDto { Send = ChannelSend.Send } } } } }; await _.Client.Events.PostEventsAsync(app_0.Id, publishRequest); // Get SMS status var messageBird = new MessageBirdClient(AccessKey); var text = $"<start>{subjectId}</end>"; using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60))) { while (!cts.IsCancellationRequested) { var messages = await messageBird.GetMessagesAsync(200); if (messages.Items.Any(x => x.Body == text && x.Recipients.Items[0].Status == "delivered")) { return; } await Task.Delay(1000); } } Assert.False(true, "SMS not sent."); }