mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 18:58:10 +00:00
commit
3e513f5c05
@ -88,6 +88,28 @@ class WebhooksController < ActionController::Base
|
||||
render nothing: true, status: 200
|
||||
end
|
||||
|
||||
def sparkpost
|
||||
events = params["_json"] || [params]
|
||||
events.each do |event|
|
||||
message_id = event["msys"]["message_event"]["campaign_id"] rescue nil
|
||||
bounce_class = event["msys"]["message_event"]["bounce_class"] rescue nil
|
||||
next unless message_id && bounce_class
|
||||
|
||||
bounce_class = bounce_class.to_i
|
||||
|
||||
# bounce class definitions: https://support.sparkpost.com/customer/portal/articles/1929896
|
||||
if bounce_class < 80
|
||||
if bounce_class == 10 || bounce_class == 25 || bounce_class == 30
|
||||
process_bounce(message_id, SiteSetting.hard_bounce_score)
|
||||
else
|
||||
process_bounce(message_id, SiteSetting.soft_bounce_score)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
render nothing: true, status: 200
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def mailgun_failure
|
||||
|
@ -20,6 +20,7 @@ Discourse::Application.routes.draw do
|
||||
post "webhooks/sendgrid" => "webhooks#sendgrid"
|
||||
post "webhooks/mailjet" => "webhooks#mailjet"
|
||||
post "webhooks/mandrill" => "webhooks#mandrill"
|
||||
post "webhooks/sparkpost" => "webhooks#sparkpost"
|
||||
|
||||
if Rails.env.development?
|
||||
mount Sidekiq::Web => "/sidekiq"
|
||||
|
@ -139,6 +139,8 @@ module Email
|
||||
@message.header['X-MJ-CustomID'] = @message.message_id
|
||||
when "smtp.mandrillapp.com"
|
||||
@message.header['X-MC-Metadata'] = { message_id: @message.message_id }.to_json
|
||||
when "smtp.sparkpostmail.com"
|
||||
@message.header['X-MSYS-API'] = { campaign_id: @message.message_id }.to_json
|
||||
end
|
||||
|
||||
# Suppress images from short emails
|
||||
|
@ -99,4 +99,28 @@ describe WebhooksController do
|
||||
|
||||
end
|
||||
|
||||
context "sparkpost" do
|
||||
|
||||
it "works" do
|
||||
user = Fabricate(:user, email: email)
|
||||
email_log = Fabricate(:email_log, user: user, message_id: message_id)
|
||||
|
||||
post :sparkpost, "_json" => [{
|
||||
"msys" => {
|
||||
"message_event" => {
|
||||
"bounce_class" => 10,
|
||||
"campaign_id" => message_id
|
||||
}
|
||||
}
|
||||
}]
|
||||
|
||||
expect(response).to be_success
|
||||
|
||||
email_log.reload
|
||||
expect(email_log.bounced).to eq(true)
|
||||
expect(email_log.user.user_stat.bounce_score).to eq(2)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user