Closed pawel2105 closed 10 years ago
Hi @pawel2105 , a couple of things:
create
method, the automatic webhook processing won't workparams[:mandrill_events]
is a json array in a string. To use Mandrill::WebHook::EventDecorator
you must JSON.parse and select an array element first. See the code https://github.com/evendis/mandrill-rails/blob/master/lib/mandrill/web_hook/processor.rb#L13@tardate after a bit of playing around I managed to get it working from:
JSON.parse(params['mandrill_events']).each do |raw_event|
event = Mandrill::WebHook::EventDecorator[raw_event]
...
end
Why did he have to do:
JSON.parse(params['mandrill_events']).each do |raw_event|
event = Mandrill::WebHook::EventDecorator[raw_event]
...
end
Mine is doing the same thing...?
Shouldn't it be calling handle_
@joshuairl Good question! No, should not need to do that. Just define the required handle_*
methods and it "should just work". If you are seeing different, then appreciate it if you could post details..
gem 'rails', '4.1.8'
gem 'mandrill-rails'
routes.rb
Rails.application.routes.draw do
resource :webhook, :controller => 'webhook', :only => [:show,:create]
#...
end
Simple webhook controller
class WebhookController < ActionController::Base
include Mandrill::Rails::WebHookProcessor
def handle_click(event_payload)
puts "EMAIL LOG: CLICK EVENT"
end
def handle_spam(event_payload)
puts "EMAIL LOG: SPAM EVENT"
end
def handle_send(event_payload)
puts "EMAIL LOG: SEND EVENT"
end
def handle_deferral(event_payload)
puts "EMAIL LOG: DEFERRAL EVENT"
end
def handle_hard_bounce(event_payload)
puts "EMAIL LOG: HARD BOUNCE EVENT"
end
def handle_reject(event_payload)
puts "EMAIL LOG: REJECT EVENT"
end
def handle_unsub(event_payload)
puts "EMAIL LOG: UNSUB EVENT"
end
def handle_open(event_payload)
puts "EMAIL LOG: OPEN EVENT"
end
def handle_soft_bounce(event_payload)
puts "EMAIL LOG: SOFT BOUNCE EVENT"
end
def handle_storage(event_payload)
puts event_payload.to_yaml
#...
end
end
Sending this with curl:
curl -v -A 'Mandrill-Webhook/1.0' -H 'X-Mandrill-Signature: [key]=' -X POST -d 'mandrill_events=[{"event":"hard_bounce","_id":"1dbc399ff23847f1a7bd5bcc047b3089","msg":{"ts":142780085,"_id":"1dbc399ff23847f1a7bd5bcc047b3089","state":"bounced","subject":"[subject]","email":"example@example.org","tags":["tag"],"smtp_events":[{"ts":1427800855,"type":"sent","diag":"250 2.0.0 OK 1427800855 s44si7119005yho.99 - gsmtp","source_ip":"198.2.128.3","destination_ip":"64.233.177.26","size":19486}],"resends":[],"_version":"n7ryzhjgtNQ7iu-681TS9g","diag":"X-Postfix; unknown user: \"[removed_email]","bgtools_code":10,"metadata":{"person":314911,"activity":17351,"attendee":410289},"sender":"[fromemail]","template":null,"bounce_description":"bad_mailbox"},"ts":1427801665}]' 'http://localhost:4000/webhook'
logs just showing:
Processing by WebhookController#create as */*
Parameters: {"mandrill_events"=>"[{\"event\":\"hard_bounce\",\"_id\":\"1dbc399ff23847f1a7bd5bcc047b3089\",\"msg\":{\"ts\":1427800854,\"_id\":\"1dbc399ff23847f1a7bd5bcc047b3089\",\"state\":\"bounced\",\"subject\":\"[subject]\",\"email\":\"example@example.org\",\"tags\":[\"tag\"],\"smtp_events\":[{\"ts\":1427800855,\"type\":\"sent\",\"diag\":\"250 2.0.0 OK 1427800855 s44si7119005yho.99 - gsmtp\",\"source_ip\":\"198.2.128.3\",\"destination_ip\":\"64.233.177.26\",\"size\":19486}],\"resends\":[],\"_version\":\"n7ryzhjgtNQ7iu-681TS9g\",\"diag\":\"X-Postfix", "unknown user: \\\"example\\\"\\n\\n--333F7821C6.1427800810\\/example.org\",\"bgtools_code\":10,\"metadata\":{\"person\":314911,\"activity\":17351,\"attendee\":410289},\"sender\":\"[fromemail]\",\"template\":null,\"bounce_description\":\"bad_mailbox\"},\"ts\":1427801665}"=>"[FILTERED]"}
sorry for my curl and log messages not making much sense but they contained data that i didn't want google indexing... haha but the entry was taken from mandrill system.
I'm seeing this same issue, is there any resolution?
@pchowdhry Hi, I've yet to find any way to reproduce the issue reported here. I just created a bare bones demo app to test again: https://github.com/evendis/mandrill-rails-demo
@joshuairl I took your example and tried to reproduce the error in the demo app. But it just worked :confounded: Perhaps you can take a look at the demo app and see if it fails for you .. or can you find a way make it fail by changing it to match your setup exactly?
Thanks @tardate I'll dig a little deeper. I think it may have something to do with the json parsing libraries, as it looks like it isn't getting the inbound event at all.
I'll appreciate that greatly, thanks @pchowdhry
I read thru the code again and the two main possibilities I can see are:
JSON.parse(params['mandrill_events'])
WebHookProcessor
injects a create method in the controller. If you (or something else) also define a create
method, it breaks the event processing
As per the documentation I've created an inbox controller:
I've copied the routes for the inbox verbatim from the readme as well. When I send a test email from the mandrill app web interface to an email address I've set up with a hook sending a POST request to mydomain.com/inbox I can see a request hit:
The params include:
Parameters: {"mandrill_events"
etc.However I cannot see any of my logging info.
Additionally I've tried to define a
create
method in the same controller and have the following in the definition:But then I get
ArgumentError: odd number of arguments for Hash