FEATURE: sparkpost webhook

This commit is contained in:
Vibol Hou
2016-09-26 22:13:34 -07:00
parent 4e663998af
commit 34af73c7cb
4 changed files with 49 additions and 0 deletions

View File

@ -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