mandrill-inbound-python icon indicating copy to clipboard operation
mandrill-inbound-python copied to clipboard

Question on inbound messages

Open fideloper opened this issue 10 years ago • 6 comments

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 avatar Dec 23 '14 03:12 fideloper

@fideloper would definitely be interesting to reach out to Mandrill to see if that would happen. If so your tweak does sound reasonable.

jpadilla avatar Dec 23 '14 12:12 jpadilla

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.

fideloper avatar Dec 23 '14 13:12 fideloper

Let's see what happens: https://twitter.com/fideloper/status/547382598972882944

fideloper avatar Dec 23 '14 13:12 fideloper

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!

fideloper avatar Dec 23 '14 16:12 fideloper

There seems to be a tweak that can be done to the README to specify this.

jpadilla avatar Dec 24 '14 20:12 jpadilla

:+1:

fideloper avatar Dec 24 '14 21:12 fideloper