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
New campaign action: Send a webhook #4357
Conversation
…ign-action-remote-call-url
…campaign-action-remote-call-url
This is brilliant! |
There was a problem hiding this 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) { | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'], |
There was a problem hiding this comment.
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?
There was a problem hiding this 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); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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
.
return; | ||
} | ||
$config = $event->getConfig(); | ||
$timeout = 10; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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? |
@Loanatik please send examples, I don't know about it |
Do we have a status on this? Any idea when it will be included? Cheers! :) |
@calevans Mautic 2.10 |
Moved to WebhookBundle
Please re-test. |
It's failing some CI tests. Please look at those when you get a minute. |
@escopecz morning. fixed |
…as they are not applicable to this scenario and added missing DELETE
There was a problem hiding this 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!
There was a problem hiding this 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! 👍
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.
Steps to test this PR: