Campaign Webhooks

Scott

Member
Possible to do webhooks upon campaign sent? So I can trigger automations for all subscribers that receive a certain autoresponder email.

 

Scott

Member
Tried to workaround by moving/copying a subscriber to a new list on campaign sent, and having a subscription webhook for that list, but seems those webhooks only trigger on a proper form submission and not on moving/copying subscriber to a new list.

Anyway I can work around the current setup to get this trigger working?
 

twisted1919

Administrator
Staff member
Possible to do webhooks upon campaign sent?
If we do this, it will slow down the sending process as now it has to wait for the webhook request to complete, so that's pretty much the reason why we haven't added such thing yet.

However, we have actual hooks in place that could help you achieve this programatically. If that's an option, we can give you more details.
 

Scott

Member
If we do this, it will slow down the sending process as now it has to wait for the webhook request to complete, so that's pretty much the reason why we haven't added such thing yet.

However, we have actual hooks in place that could help you achieve this programatically. If that's an option, we can give you more details.
Yes that's an option. Would greatly appreciate it. Thank you.
 

twisted1919

Administrator
Staff member
Awesome! So we have a hook that is triggered right after the email is sent to the subscriber. It is called "console_command_send_campaigns_after_send_to_subscriber" and it receives following params:
"Campaign $campaign, ListSubscriber $subscriber, Customer $customer, DeliveryServer $server, $sent, $response, $status"
So from apps/init-custom.php you could do:

PHP:
<?php

Yii::app()->hooks->addAction('console_command_send_campaigns_after_send_to_subscriber', function($campaign, $subscriber, $customer, $server, $sent, $response, $status) {

    // email failed sending
    if (!$sent) {
        return;
    }

    // email sent, send the webhook, look into Guzzle docs to see how to send params as well
    (new GuzzleHttp\Client())
        ->post('https://www.your-url.com/', [
            'form_params' => [
                'subscriber_email'    => $subscriber->email,
                'campaign_uid'      => $campaign->campaign_uid,
            ],
        ]);

});
 

Scott

Member
That looks great thank you so much. I'm horrible at php... but I assume I could have it modified to activate only for a specific campaign?

For example...

(I'm sure my code is wrong just an example of what I would try to achieve)

Code:
<?php

Yii::app()->hooks->addAction('console_command_send_campaigns_after_send_to_subscriber', function($campaign, $subscriber, $customer, $server, $sent, $response, $status) {

// email failed sending
if (!$sent) {
return;
}

// specific campaign is matched
if ($campaign_uid = "od5423fj94232")
else {
return;
}

// email sent, send the webhook, look into Guzzle docs to see how to send params as well
(new GuzzleHttp\Client())
->post('https://www.your-url.com/', [
'form_params' => [
'subscriber_email'    => $subscriber->email,
'campaign_uid'      => $campaign->campaign_uid,
],
]);

});
 

laurentiu

Active Member
Staff member Support Staff MailWizz 2.0 Tester
but I assume I could have it modified to activate only for a specific campaign?
PHP:
<?php

Yii::app()->hooks->addAction('console_command_send_campaigns_after_send_to_subscriber', function($campaign, $subscriber, $customer, $server, $sent, $response, $status) {

    // email failed sending
    if (!$sent) {
        return;
    }


    if ($campaign->campaign_uid == "here_campaign_uid") {
        // email sent, send the webhook, look into Guzzle docs to see how to send params as well
        (new GuzzleHttp\Client())
            ->post('https://www.your-url.com/', [
                'form_params' => [
                    'subscriber_email'    => $subscriber->email,
                    'campaign_uid'      => $campaign->campaign_uid,
                ],
            ]);
    }
    
});
 

Scott

Member
That's amazing thank you both very much. One last question.

If I implement this code could it slow down the sending of my other campaigns? Or will it only have an effect on the campaign that matches that specific campaign id?
 
Top