mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:53:49 +08:00
FEATURE: mailjet webhook
This commit is contained in:
@ -38,7 +38,8 @@ class WebhooksController < ActionController::Base
|
||||
end
|
||||
|
||||
def sendgrid
|
||||
params["_json"].each do |event|
|
||||
events = params["_json"] || [params]
|
||||
events.each do |event|
|
||||
if event["event"] == "bounce".freeze
|
||||
if event["status"]["4."]
|
||||
sendgrid_process(event, Email::Receiver::SOFT_BOUNCE_SCORE)
|
||||
@ -53,6 +54,21 @@ class WebhooksController < ActionController::Base
|
||||
render nothing: true, status: 200
|
||||
end
|
||||
|
||||
def mailjet
|
||||
events = params["_json"] || [params]
|
||||
events.each do |event|
|
||||
if event["event"] == "bounce".freeze
|
||||
if event["hard_bounce"]
|
||||
mailjet_process(event, Email::Receiver::HARD_BOUNCE_SCORE)
|
||||
else
|
||||
mailjet_process(event, Email::Receiver::SOFT_BOUNCE_SCORE)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
render nothing: true, status: 200
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def mailgun_failure
|
||||
@ -101,4 +117,15 @@ class WebhooksController < ActionController::Base
|
||||
Email::Receiver.update_bounce_score(email_log.user.email, bounce_score)
|
||||
end
|
||||
|
||||
def mailjet_process(event, bounce_score)
|
||||
message_id = event["CustomID"]
|
||||
return if message_id.blank?
|
||||
|
||||
email_log = EmailLog.find_by(message_id: message_id)
|
||||
return if email_log.nil?
|
||||
|
||||
email_log.update_columns(bounced: true)
|
||||
Email::Receiver.update_bounce_score(email_log.user.email, bounce_score)
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user