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
[3.0] Support BlockKit / WebAPI-based bot notifications #64
Conversation
Should be a separate, new channel to avoid breaking change. |
@taylorotwell can't we instruct people to use this package's v2 version if they need the old version? |
I don't see any reason to not just make it a new channel. It's just so easy to avoid the breaking change entirely by doing so. We already take a similar approach to our SES and SES 2.0 drivers for mail. |
Sounds good to me & shouldn't be too difficult. I'll probably pick it up tomorrow morning, as I don't have time for it today. I'll ping you when it's done. 👍 |
Thanks! Just mark as ready for review when done and I'll take a look. |
Can you copy of your usage examples into this PR and update them as necessary since it is a new channel? Thanks. |
@taylorotwell The usage remains unchanged! The internal channel (Webhook vs. WebAPI) is determined based on whether the Part of the reason for this, has to do with the fact that the v2 version uses the The reason for this has to do with that I wasn't sure which one deserves the "slack" channel type more, and only one channel (I think?) can have it at a time. With the webhooks being legacy, changing them would break backwards compatibility. |
src/Slack/SlackChannel.php
Outdated
|
||
return $this->http->asJson() | ||
->withToken($route->token) | ||
->post('https://slack.com/api/chat.postMessage', $payload); |
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'm not sure what the precedence is in other notification channels, but while testing I spent a long time not receiving notifications until I realised I needed to add the Slack app into each channel I wanted to receive notifications for.
I wonder whether we should throw an exception depending on the response?
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.
Yeah, that actually makes a lot of sense. Fixed. 👍
It'll now throw on non-200's, as well as when the response itself gets checked, and if a Slack "non-ok" response is given, it'll throw an exception that includes the "error" property from the error. This can range from permission issues, to non-existent channels and even invalid authentication tokens.
src/Slack/SlackChannel.php
Outdated
$payload = $this->buildJsonPayload($message, $route); | ||
|
||
if (! $route->token || ! $payload['channel']) { | ||
return null; |
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.
If you're not sending a token / channel then perhaps we should throw an exception so that the developer can figure out what is missing? As per-below, I'm not sure what the situation is across other channels, but it's very easy to not receive notifications and have no direction as to how to resolve it.
@claudiodekker I started to use the new major version on my small project and had some issues with tests that I solved. I just wanty to share my experience ti save someones time.
$this->app->singleton(SlackWebhookChannel::class, function () {
$httpClientHandler = new MockHandler([
new \GuzzleHttp\Psr7\Response(200),
]);
$handlerStack = HandlerStack::create($httpClientHandler);
return new SlackWebhookChannel(new \GuzzleHttp\Client(['handler' => $handlerStack]));
}); But in my case it was even simpler: I just needed to fake Event dispatcher because I send Slack notification from an Event Listener: $fakeEvent = \Illuminate\Support\Facades\Event::fake();
...
$fakeEvent->assertDispatched(OrderPaid::class); |
@claudiodekker, great PR. Unfortunately I think backwards compatibility was broken anyway - or at least the upgrade path isn't totally clear. We are returning
It looks like For now we are down-grading to 2.5 to ensure this is working until we can commit to the conversion to the block API. |
Re-submit of #63 using a clean commit history, as requested.
My reasoning for removing the v2 API & considering this a full v3 is pretty simple: Although Incoming Webhooks still work today, they have been marked as deprecated in favor of the WebAPI that this PR (in part) implements: https://api.slack.com/legacy/custom-integrations/messaging/webhooks
Since this constitutes a breaking change, I've also taken the opportunity to remove deprecated/no-longer-supported Laravel and PHP versions. Those who still rely on the now-deprecated legacy webhooks can lock the composer dependency to^2.0
until this API is eventually removed by Slack altogether.