Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New campaign action: Send a webhook #4357

Merged
merged 27 commits into from Aug 16, 2017

Conversation

kuzmany
Copy link
Member

@kuzmany kuzmany commented Jul 5, 2017

Q A
Bug fix?
New feature? y
Related user documentation PR URL mautic/documentation#204
Related developer documentation PR URL
Issues addressed (#s or URLs) #854
BC breaks?
Deprecations?

Description:

Just add new action with curl call to url
Return true If response code = 200 or 201.

Note: this PR contains #4355 which should be merged first.

Thanks to @Loanatik for donate this feature.

image

Steps to test this PR:

  1. Basic test could be create test.php anywhere and call GET or POST there.
  2. Extended test could be with service external service. (I tested with our private address validator service and works with POST request data and headers). Maybe people from [feature] Campaign action for remote api call (post, put, delete, get) #854 could test

@Loanatik
Copy link

Loanatik commented Jul 5, 2017

This is brilliant!

@escopecz escopecz added feature A new feature for inclusion in minor or major releases needs-documentation PR's that need documentation before they can be merged ready-to-test PR's that are ready to test labels Jul 6, 2017
Copy link
Sponsor Member

@escopecz escopecz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Zdeno! This feature has been requested many times.

I added some thoughts to the new code, but over all, it looks good to me! Please review the comments and implement them if they make sense to you.

return $event->setResult(true);
}
} catch (\Exception $e) {
}
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to let the users know why the request failed. It fails silently without any clue of what happened. Whether it returned 500 or timeouted. Could you please add some error messages so the users won't report errors like "the campaign URL call doesn't work", but give them information so they could debug themselves?

You can inspire here: https://github.com/mautic/mautic/blob/staging/app/bundles/PluginBundle/EventListener/CampaignSubscriber.php#L116

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improved. Please check it

*/
protected $connector;

/**
* CampaignSubscriber constructor.
*
* @param IpLookupHelper $ipLookupHelper
* @param AuditLogModel $auditLogModel
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the new dependency to the annotation please.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

$data = array_flip(AbstractFormFieldHelper::parseList($data));
if (in_array($method, ['get', 'trace'])) {
$response = $this->connector->$method(
$config['url'],
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the $data should be added as a URL query params in this case?

@escopecz escopecz added pending-feedback PR's and issues that are awaiting feedback from the author and removed ready-to-test PR's that are ready to test labels Jul 6, 2017
@escopecz escopecz self-assigned this Jul 6, 2017
Copy link
Sponsor Member

@escopecz escopecz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was fast!

}
if (in_array($response->code, [200, 201])) {
return $event->setResult(true);
}
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also add something like

else {
    $event->setFailed('Response returned HTTP code '.$response->code);
}

I'm not sure whether the error is run through the translator later. Maybe you'll have to add Translator as a dependency to this Subscriber.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, should be resolved with the previous commit

return $event->setResult(true);
}
} catch (\Exception $e) {
return $event->setResult($e->getMessage());
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method should be setFailed instead of setResult.

@kuzmany kuzmany changed the title New campaign action: Call remote url New campaign action: Call remote url (magic stick) Jul 6, 2017
@escopecz escopecz added ready-to-test PR's that are ready to test and removed pending-feedback PR's and issues that are awaiting feedback from the author labels Jul 6, 2017
return;
}
$config = $event->getConfig();
$timeout = 10;
Copy link

@Loanatik Loanatik Jul 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does timeout get set to the value specified by the user?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, already update with timeout option. Check screenshot

image

@Loanatik
Copy link

Loanatik commented Jul 7, 2017

Rather than just an authorization header, wouldn't make more sense to allow any custom header similar to the way you can add any data?

@kuzmany
Copy link
Member Author

kuzmany commented Jul 7, 2017

@Loanatik please send examples, I don't know about it

@Loanatik
Copy link

Loanatik commented Jul 7, 2017

I don't personally have a big need for this, though I'd imagine others will:
image

I have not tested the data section for tokens. Am I correct in assuming that that they should work?

@kuzmany kuzmany changed the title New campaign action: Call remote url (magic stick) New campaign action: Send a webhook Jul 14, 2017
@alanhartless alanhartless added this to the 2.10.0 milestone Jul 24, 2017
@matishaladiwala matishaladiwala modified the milestone: 2.10.0 Jul 24, 2017
@calevans
Copy link

Do we have a status on this? Any idea when it will be included?

Cheers! :)
=C=

@kuzmany
Copy link
Member Author

kuzmany commented Jul 31, 2017

@calevans Mautic 2.10

@kuzmany
Copy link
Member Author

kuzmany commented Jul 31, 2017

Please re-test.
Refactor to Send a webhook and moved to MauticWebhookBundle.

@escopecz
Copy link
Sponsor Member

escopecz commented Aug 1, 2017

It's failing some CI tests. Please look at those when you get a minute.

@kuzmany
Copy link
Member Author

kuzmany commented Aug 1, 2017

@escopecz morning. fixed

Copy link
Contributor

@alanhartless alanhartless left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed trace and options as they are not applicable to webhooks and added the missing DELETE method to the method choices. I also added a not blank validator to ensure URL is required. Otherwise, good stuff!

@alanhartless alanhartless added the pending-test-confirmation PR's that require one test before they can be merged label Aug 4, 2017
Copy link
Sponsor Member

@escopecz escopecz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great. Amazing feature. Thanks! 👍

@escopecz escopecz added ready-to-commit PR's with 2 successful tests, 1 approval, automated tests and docs and is ready to be merged and removed pending-test-confirmation PR's that require one test before they can be merged ready-to-test PR's that are ready to test labels Aug 7, 2017
@escopecz escopecz merged commit aa5d126 into mautic:staging Aug 16, 2017
@kuzmany kuzmany deleted the campaign-action-remote-call-url branch April 7, 2018 17:52
@escopecz escopecz removed ready-to-commit PR's with 2 successful tests, 1 approval, automated tests and docs and is ready to be merged labels Oct 2, 2018
@ghost
Copy link

ghost commented May 21, 2020

Does it support the payload like in the attached picture
Screenshot from 2020-05-21 21-20-37
Also how do i know the status / response of a api call in send a webhook

@dichvuhuuich
Copy link

Does it support the payload like in the attached picture
Screenshot from 2020-05-21 21-20-37
Also how do i know the status / response of a api call in send a webhook

I want to know the status / response of a api call in send a webhook, too, do you know that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature for inclusion in minor or major releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants