Search code examples
phpsymfonybundleslack-apisymfony-3.4

How to use multiple endpoints for Symfony NexySlackBundle


I am using the nexylan/slack Bundle for my symfony 3.4 application. I configured the slack Incoming WebHook for #general channel and it's working as expected. The bundle configuration looks something like:

nexy_slack:

    # If you want to use an another httplug client service.
    http:
        client: httplug.client

    # The Slack API Incoming WebHooks URL.
    endpoint:             https://hooks.slack.com/services/ABCD/987ABC
    channel:              null
    username:             null
    icon:                 null
    link_names:           false
    unfurl_links:         false
    unfurl_media:         true
    allow_markdown:       true
    markdown_in_attachments: []

Now I have another channel called #dev and I've added the Incoming WebHook and received the endpoint. I also want to send messages to the dev channel.

My question is, how can I configure the dev channel endpoint too in order to use it. Is there any way I can do this?

Here is the Slack Bundle


Solution

  • It looks like the bundle only supports 1 endpoint. If you want to have multiple endpoints you either have to fork or send in a PR.

    Basically what you need to do, is adjust both files in src/DependencyInjection.

    In Configuration.php you need to ensure that you can define multiple endpoints by adding a parent array node, e.g. called endpoints. Then inside NexySlackExtension you can foreach through each endpoint configuration and do the same configuration as before just add a prefix or suffix. So something like:

    $configuration = new Configuration();
    $endpointConfigs = $this->processConfiguration($configuration, $configs);
    
    foreach ($endpointConfigs['endpoints'] as $config) {
        // ....
    }
    

    You might also want do add some special handling for a "default" endpoint. This should already do the trick, although it might need some adjustments as I haven't looked into the Bundle in detail. Maybe you can also contact the author via a ticket in the Issue tracker and they can help you write a PR.