sisimai / rb-sisimai

Mail Analyzing Interface for email bounce: A Ruby library to parse RFC5322 bounce mails and generating structured data as JSON from parsed results. Ruby version of Sisimai: an error mail analyzer.
https://libsisimai.org/
Other
83 stars 19 forks source link

SendGrid Webhook compatibility #306

Open benstaf opened 3 months ago

benstaf commented 3 months ago

Many apps are automatically compatible with SendGrid Webhook response format (it's the market leader):

https://www.twilio.com/docs/sendgrid/for-developers/tracking-events/event#example-webhook-response-5

On the other hand, making an app accept Sisimai webhook requires some customization:

https://libsisimai.org/en/start/

Is it possible to have a standardized SendGrid format output, so that it's automatically compatible with apps designed for SendGrid ?

azumakuniyuki commented 3 months ago

We actually implemented this feature experimentally in 2016 but removed it in 2019 due to the following three reasons: https://github.com/sisimai/rb-sisimai/tree/v4.25.0/lib/sisimai/bite/json

  1. The response obtained from the webhook contains less information for identifying the bounce reason compared to the bounce email itself.
  2. SendGrid already provides sufficient bounce analysis.
  3. Although we implemented it experimentally, we did not receive any specific feedback from users regarding this feature, so we judged that it was not a feature that Sisimai users were looking for.

If you want to convert the JSON returned from SendGrid to a format compatible with Sisimai, the following code might be helpful. https://github.com/sisimai/rb-sisimai/blob/v4.25.0/lib/sisimai/bite/json/sendgrid.rb

benstaf commented 3 months ago

I plan to do the opposite: convert the JSON returned by Sisimai into a SendGrid JSON, because SendGrid format is already supported by most mailing apps

This option would facilitate adoption of Sisimai

azumakuniyuki commented 3 months ago

I understand what you're trying to achieve. If you're aiming to convert the data structure outputted by Sisimai into a format compatible with SendGrid, I believe that writing a script like the following would be the most concise, logical, and efficient approach.

#! /usr/bin/env ruby
require 'sisimai'
require 'oj'
v = Sisimai.rise('/path/to/mbox')
s = [] # SendGrid compatible format

if v.is_a? Array
  v.each do |e|
    r = {
      'email' => e.recipient.address,
      'event' => 'bounce',
      ... other fields
    }
    s << r
  end
end
j = Oj.dump(s) if s.size > 0