MeteorJS Mailgun Webhook Bounced Event

时间:2016-07-27 12:56:33

标签: meteor webhooks multipart mailgun

我试图点击mailgun的webhook并在meteorjs中接收数据。我在Router处理了该活动,但在bounced活动期间,我在req.body找不到任何内容。

以下是我的代码:

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
    };

1 个答案:

答案 0 :(得分:1)

Mailgun API所述,bounced事件不包含body字段