add postmark webhook handling (#8919)

This commit is contained in:
Jay Pfaffman 2020-02-11 07:09:07 -08:00 committed by GitHub
parent b266129ce5
commit d294e13225
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 0 deletions

View File

@ -63,6 +63,23 @@ class WebhooksController < ActionController::Base
success
end
def postmark
# see https://postmarkapp.com/developer/webhooks/bounce-webhook#bounce-webhook-data
# and https://postmarkapp.com/developer/api/bounce-api#bounce-types
message_id = params["MessageID"]
to_address = params["Email"]
type = params["Type"]
case type
when "HardBounce", "SpamNotification", "SpamComplaint"
process_bounce(message_id, to_address, SiteSetting.hard_bounce_score)
when "SoftBounce"
process_bounce(message_id, to_address, SiteSetting.soft_bounce_score)
end
success
end
def sparkpost
events = params["_json"] || [params]
events.each do |event|

View File

@ -18,6 +18,7 @@ Discourse::Application.routes.draw do
post "webhooks/mailgun" => "webhooks#mailgun"
post "webhooks/mailjet" => "webhooks#mailjet"
post "webhooks/mandrill" => "webhooks#mandrill"
post "webhooks/postmark" => "webhooks#postmark"
post "webhooks/sendgrid" => "webhooks#sendgrid"
post "webhooks/sparkpost" => "webhooks#sparkpost"

View File

@ -138,6 +138,40 @@ describe WebhooksController do
end
end
context "postmark" do
it "works" do
user = Fabricate(:user, email: email)
email_log = Fabricate(:email_log, user: user, message_id: message_id, to_address: email)
post "/webhooks/postmark.json", params: {
"Type"=> "HardBounce",
"MessageID"=> message_id,
"Email"=> email
}
expect(response.status).to eq(200)
email_log.reload
expect(email_log.bounced).to eq(true)
expect(email_log.user.user_stat.bounce_score).to eq(SiteSetting.hard_bounce_score)
end
it "soft bounces" do
user = Fabricate(:user, email: email)
email_log = Fabricate(:email_log, user: user, message_id: message_id, to_address: email)
post "/webhooks/postmark.json", params: {
"Type"=> "SoftBounce",
"MessageID"=> message_id,
"Email"=> email
}
expect(response.status).to eq(200)
email_log.reload
expect(email_log.bounced).to eq(true)
expect(email_log.user.user_stat.bounce_score).to eq(SiteSetting.soft_bounce_score)
end
end
context "sparkpost" do
it "works" do
user = Fabricate(:user, email: email)