Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MeteorJS Mailgun Webhook Bounced Event

I'm trying to tap the webhook of mailgun and receive the data in meteorjs. I'm handling the event in Router, however during the bounced event, I find nothing in req.body.

Below is my code:

Router.route('/api/v1/mailgun/hooks',{ where: 'server' })
.post(function() {
    Router.onBeforeAction(Iron.Router.bodyParser.urlencoded({
        extended: false
    }));

    this.response.setHeader('access-control-allow-origin', 'mailgun.com');
    var req = this.request;
    var res = this.response;
    var values = req;

    res.end('Well this is the end');

    // console.log('The event is ', values);
    var campaignId, campaignId1, recipient, message_id, timestamp, domain, city, client_name, client_os, client_type,
        country, device_type, user_agent, ip_address, url = '',event;

    if (values.event == 'delivered') {
        //Key Values
        domain = values['domain'];
        event = values['event'];
        t_camp = values['X-Mailgun-Tag'];
        campaignId = t_camp.split(":")[1];
        message_id = values['Message-Id'];
        recipient = values['recipient'];
        timestamp = values['timestamp'];
        //Key Values
    }

    if (values.event == 'opened' || values.event == 'clicked') {
        //Key Values
        domain = values['domain'];
        event = values['event'];
        t_camp = values['tag'];
        campaignId = t_camp.split(":")[1];
        message_id = values['message-id'];
        recipient = values['recipient'];
        timestamp = values['timestamp'];
        //Key Values

        city = values['city'];
        ip_address = values['ip'];
        client_name = values['client-name'];
        client_os = values['client-os'];
        client_type = values['client-type'];
        country = values['country'];
        device_type = values['device-type'];
        user_agent = values['user-agent'];
    }


    if (values.event == 'clicked') {
        url = values['url'];
    }

    // if (values.event == 'unsubscribed' || values.event == 'bounced' || values.event == 'dropped' || values.event == 'rejected' || values.event == 'failed') {
    if (values.event == 'rejected' || values.event == 'failed') {
        //Key Values
        domain = values['domain'];
        event = values['event'];
        t_camp = values['tag'];
        campaignId = t_camp.split(":")[1];
        message_id = values['message-id'];
        recipient = values['recipient'];
        timestamp = values['timestamp'];
        //Key Values

        city = values['city'];
        ip_address = values['ip'];
        client_name = values['client-name'];
        client_os = values['client-os'];
        client_type = values['client-type'];
        country = values['country'];
        device_type = values['device-type'];
        user_agent = values['user-agent'];
    }
    data = {
        'domain': domain,
        'event': event,
        'campaign': campaignId,
        'message': message_id,
        'recipient': recipient,
        'timestamp': timestamp,
        'city': city,
        'ip_address': ip_address,
        'client_name': client_name,
        'client_os': client_os,
        'client_type': client_type,
        'country': country,
        'device_type': device_type,
        'user_agent': user_agent,
        'url': url
    };
like image 669
Jayanth Avatar asked Jul 27 '16 12:07

Jayanth


1 Answers

As stated in the Mailgun API, the bounced event does not include a body field

like image 103
StephenG Avatar answered Oct 13 '22 12:10

StephenG