laravel/slack-notification-channel

RuntimeException: Slack API call failed with error [channel_not_found] when trying to send messages to my slack channel

Closed this issue · 2 comments

Slack Notification Channel Version

3.2.0

Laravel Version

10.10

PHP Version

8.1.22+

Database Driver & Version

No response

Description

Full error is:
RuntimeException: Slack API call failed with error [channel_not_found]. in file .../vendor/laravel/slack-notification-channel/src/Slack/SlackChannel.php on line 57. Code that breaks looks as follow:

$response = $this->http->asJson()
      ->withToken($route->token)
      ->post('https://slack.com/api/chat.postMessage', $payload)
      ->throw();

Maybe I am using this library wrong, but when trying to send a Slack notification I had to overwrite the SlackChannel::send() method on line 53 to accept a URL to post (a webhook URL from my Slack App) instead of the hardcoded 'https://slack.com/api/chat.postMessage' url.
I am not sure why this line is hardcoded, maybe I am supposed to use another method for webhooks or maybe this method has not been updated with Slack API changes.
I am suggesting to change the line to:
->post(config('services.slack.notifications.webhook_url'), $payload)
which it's what I had to do to be able to send messages to my slack channel using this library. This fixed my problem

Steps To Reproduce

  1. Create a slack app that supports webhooks.
  2. Have a notification configured to send messages via Slack:
  3. Try to send message, using Notifiable or dispatching it now:
Notification::route('slack', config('services.slack.notifications.channel'))
                ->notify(new HorizonJobFailed($errorMessage));

Error will be thrown not being able to find the correct channel, since URL to post does not match webhook url

Hi there,

Thanks for reporting but it looks like this is a question which can be asked on a support channel. Please only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repo you can try one of the following channels:

However, this issue will not be locked and everyone is still free to discuss solutions to your problem!

Thanks.

@gaboeremita did you solve your issue?

I'm facing with the same problem