Repository navigation
Add the campaign subscription topic and campaigns webhooks #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: add-subscription-topics-to-the-sdks-and
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ namespace Mailtrap.Webhooks.Models; | |
|
|
||
|
|
||
| /// <summary> | ||
| /// Event type the <c>email_sending</c> webhook can subscribe to. | ||
| /// Event type the <c>email_sending</c> and <c>campaigns</c> webhooks can subscribe to. | ||
| /// </summary> | ||
| public sealed record WebhookEventType : StringEnum<WebhookEventType> | ||
| { | ||
|
|
@@ -50,4 +50,15 @@ public sealed record WebhookEventType : StringEnum<WebhookEventType> | |
| /// Gets the value representing "reject" event. | ||
| /// </summary> | ||
| public static readonly WebhookEventType Reject = Define("reject"); | ||
|
|
||
| /// <summary> | ||
| /// Gets the value representing "subscription_preferences_update" event: | ||
| /// a recipient changed their subscription preferences. | ||
| /// </summary> | ||
| /// | ||
| /// <remarks> | ||
| /// Available only for <c>campaigns</c> webhooks and <c>email_sending</c> webhooks of the bulk stream; | ||
| /// the API rejects it for the transactional stream. | ||
| /// </remarks> | ||
| public static readonly WebhookEventType SubscriptionPreferencesUpdate = Define("subscription_preferences_update"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [should] The live API doesn't accept |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,8 @@ namespace Mailtrap.Webhooks.Validators; | |
| /// <summary> | ||
| /// Validator for <see cref="CreateWebhookRequest"/>.<br/> | ||
| /// Ensures Url is an absolute URI, WebhookType is set, | ||
| /// and that <c>email_sending</c> webhooks specify SendingStream and EventTypes. | ||
| /// that <c>email_sending</c> webhooks specify SendingStream and EventTypes, | ||
| /// and that <c>campaigns</c> webhooks specify EventTypes and no SendingStream. | ||
| /// </summary> | ||
| public sealed class CreateWebhookRequestValidator : AbstractValidator<CreateWebhookRequest> | ||
| { | ||
|
|
@@ -33,10 +34,20 @@ public CreateWebhookRequestValidator() | |
| RuleFor(r => r.SendingStream) | ||
| .NotNull() | ||
| .WithMessage("'SendingStream' is required for 'email_sending' webhook type."); | ||
| }); | ||
|
|
||
| When(r => r.WebhookType == WebhookType.Campaigns, () => | ||
| { | ||
| RuleFor(r => r.SendingStream) | ||
| .Null() | ||
| .WithMessage("'SendingStream' must not be set for 'campaigns' webhook type."); | ||
| }); | ||
|
|
||
| When(r => r.WebhookType == WebhookType.EmailSending || r.WebhookType == WebhookType.Campaigns, () => | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [could] No test covers the |
||
| { | ||
| RuleFor(r => r.EventTypes) | ||
| .Must(events => events is { Count: > 0 }) | ||
| .WithMessage("'EventTypes' must contain at least one event for 'email_sending' webhook type."); | ||
| .WithMessage(r => $"'EventTypes' must contain at least one event for '{r.WebhookType}' webhook type."); | ||
|
Rabsztok marked this conversation as resolved.
Resolved
|
||
| }); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The API ignores this field only when subscription topics aren't enabled for the account. An account that has the feature but no topic with this ID gets a 422 "does not exist", so "an account without subscription topics" reads wrong for that case. The same sentence is in
UpdateEmailCampaignRequest.