Skip to content

Slack notifier SlackTransport doesn't parse Slack DSN correctly #39204

Closed
@r-ichard

Description

@r-ichard

Symfony version(s) affected: 5.1.*

Description
When I set my webhook url as DSN like this :

SLACK_DSN=slack://hooks.slack.com/services/xxxxx/xxxxx/xxxxx

Slack notification doesn't work as the post URL in SlackTransport.php becomes:

https://hooks.slack.com/services/services/xxxxx/xxxxx/xxxxx

A confusing exception is thrown as Slack responds with HTTP 200 and the content of the https://api.slack.com page.
"Unable to post the Slack message: ..."

How to reproduce

  • Install symfony/slack-notifier
  • Set Slack DSN as (no https unless an other error will trigger) :
    SLACK_DSN=slack://hooks.slack.com/services/YOUR/CUSTOM/WEBHOOK-URL
  • Try to send a Slack notification.

Possible Solution

The only way to make it work is to remove "/services" from the webhook URL in DSN as:

SLACK_DSN=slack://hooks.slack.com/xxxxx/xxxxx/xxxxx

Another solution would be to fix symfony/slack-notifier by modifying SlackTransport.php:

        $response = $this->client->request('POST', sprintf('https://%s/services/%s', $this->getEndpoint(), $id), [
            'json' => array_filter($options),
        ]);

to

        $response = $this->client->request('POST', sprintf('https://%s/%s', $this->getEndpoint(), $id), [
            'json' => array_filter($options),
        ]);

Additional information
The main issue is that the correct syntax for Slack DSN with webhook is unclear in the documentation.
I had to guess the syntax by myself. Maybe this issue just requires a documentation update.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions