mandrill-inbound-python
mandrill-inbound-python copied to clipboard
Question on inbound messages
Mandrill sends an array of objects, I'm wondering if there are cases where you get multiple messages per event?
It looks like the code assumes the first item in the returned array: https://github.com/jpadilla/mandrill-inbound-python/blob/master/mandrill_inbound/init.py#L18
Would it be accurate to change the example from:
json_data = json.loads(open('./tests/fixtures/valid_http_post.json').read())
inbound = MandrillInbound(source=json_data)
to
json_data = json.loads(open('./tests/fixtures/valid_http_post.json').read())
inbound = MandrillInbound(source=json_data[0])
?
Thanks, great helper library!
@fideloper would definitely be interesting to reach out to Mandrill to see if that would happen. If so your tweak does sound reasonable.
I'll ask them, it would be worth knowing how that works - perhaps multiple events come through if they queue up events due to a failed webhook call, for example.
Let's see what happens: https://twitter.com/fideloper/status/547382598972882944
Response: https://twitter.com/mandrillapp/status/547420420933046272
As we process webhook events, if they happen really close in time, we will batch them together and send a single webhook POST (up to 1000 events) instead of making a separate webhook POST for each event.
I personally did a loop in my code, which works with the library's current version:
mandrillInput = request.form['mandrill_events']
eventJson = json.loads(mandrillInput)
for message in eventJson:
inbound = MandrillInbound(source=message)
msg = {
'from_name': inbound.sender[0],
'from_email': inbound.sender[1],
'html': inbound.html_body,
'test': inbound.text_body,
'subject': inbound.subject,
'to': [{'email': '[email protected]', 'name': 'Chris Fidao', 'type': 'to'}]
}
# Process msg further...
This seems to work fine, which leads me to believe one of the examples might need to explicitly state that it should get passed a single object (dict) rather than an array of dicts - I think, if I'm reading it right!
Thanks!
There seems to be a tweak that can be done to the README to specify this.
:+1: