This tutorial has a new version, check it out!

Installing Bundles with "Average" Docs

Keep on Learning!

If you liked what you've learned so far, dive in!
Subscribe to get access to this tutorial plus
video, code and script downloads.

Start your All-Access Pass
Buy just this tutorial for $10.00

With a Subscription, click any sentence in the script to jump to that part of the video!

Login Subscribe

Let's do something fun! Google for SlackBundle - you'll find one called nexylan/slack-bundle. This is a fun library that gives us a service that can send messages to a Slack channel. To install it, find the composer require line, copy that, move over to your terminal and paste:

composer require nexylan/slack-bundle:2.2.0 php-http/guzzle6-adapter:1.1.1

Interesting: this installs the bundle and some other library called guzzle6-adapter. Wait for it to install and... it fails!

Don't panic. There are two important things happening. First, this installed two bundles! Cool! You can see both of them inside bundles.php:

... lines 1 - 2
return [
... lines 4 - 11
Http\HttplugBundle\HttplugBundle::class => ['all' => true],
Nexy\SlackBundle\NexySlackBundle::class => ['all' => true],
];

For the SlackBundle, it says "auto-generated recipe". That means that the bundle doesn't actually have a recipe... but Symfony Flex, at least added it to bundles.php for us. By the way, this is not necessarily a bad thing: sometimes a bundle doesn't really need a custom recipe!

The second bundle did have a recipe. Before I started recording, I committed my changes so far. To see what that recipe did, let's run:

git status

Interesting: it added a new configuration file called httplug.yaml:

httplug:
plugins:
redirect:
preserve_header: true
discovery:
client: 'auto'
clients:
app:
http_methods_client: true
plugins:
- 'httplug.plugin.content_length'
- 'httplug.plugin.redirect'

We don't know what this does, but it probably configures some sensible defaults. Let's ignore it unless the docs tells us otherwise.

When composer require Fails

The second important thing I want to talk about is... well... this big error!

The child node "endpoint" at path "nexy_slack" must be configured.

Oof... this is not a great error message. It means that this bundle requires some configuration, which we don't have yet. And since it didn't add a configuration file via a recipe, we'll need to create it ourselves. But before we do that, the most important thing to understand is this: when you see an error like this after running composer require, Composer did finish successfully and the library was installed.

Configuring the Slack Endpoint

Ok, let's go read the docs so we can figure out how to configure this bundle. Ah, so one of the reasons that installing this bundle isn't smoother is that its documentation is out-of-date! Hopefully it will be updated soon, but actually, this is a great example of how to navigate less-than-up-to-date docs.

How do I know it's out-of-date? This AppKernel thing is a Symfony 3 concept. We don't need to worry about enabling bundles: this is done for us automatically.

If you scroll down... ah, here is the configuration. And it says that this is an example of default values... which probably means that we don't need to copy all of this. Yep, we just need to fill in the parts that are required, so, endpoint.

Let's copy part of the configuration file. But... it doesn't tell us where to put this! That's ok! We already know: it can live in any file in config/packages. Let's create a new one called nexy_slack.yaml. Paste the config, but the only key we need is endpoint:

nexy_slack:
... lines 2 - 3

If you're coding along, here's how this will work. First, you'll need access to a Slack workspace where you're an admin. If you don't have one, you can create one: it's free and easy.

Once you've got it, go to your domain /apps/manage, then search the App Directory for "Incoming Webhooks". Click "Add Configuration" to setup a new webhook: I've already done this.

Thanks to this, you now have a new Webhook URL, which anyone can use to send messages to your Slack. There's no authentication - the URL is meant to be a secret. Um... yea, I know you can read mine - I'm super bad at secrets. I'll invalidate it after I record.

Copy the URL and paste it next to endpoint:

nexy_slack:
endpoint: 'https://hooks.slack.com/services/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'

Now, move over and clear your cache:

php bin/console cache:clear

Again, starting in Symfony 4.0.5, you will not need to clear your cache when adding a new config file.

What is $this->get()?

Sweet! The bundle is configured, so... how do we use it? Go back to the docs. Below, yea! Usage! And this is where things get really interesting. The code says $this->get('nexy_slack.client). What the heck is that?

Actually, this is something from Symfony 3... which we do not recommend doing in Symfony 4 and may or may not work, depending on the situation. Basically, $this->get() is, or was, a shortcut to fetch a service by its id. Instead of doing this, we are - of course - going to fetch the service via autowiring.

You guys know the drill: find your terminal and run:

php bin/console debug:autowiring

And search for "Slack". Wait... nothing!

Yep... this bundle technically works with Symfony 4... but it hasn't been fully updated. And so, it doesn't expose any services for autowiring! Right now, there is no way to autowire that nexy_slack.client service.

We need to learn a little bit more about public versus private services. And then take control of things with an autowiring alias!

Leave a comment!

  • 2020-04-08 Vladimir Sadicov

    Hey @Anneleen Peeters

    I guess you got newer version of nexylan/slack-bundle so in next chapter there is a TIP that you should remove Nexy\Slack\Client: '@nexy_slack.client' binding from config/services.yaml file because it already configured by bundle!

    Cheers!

  • 2020-04-06 Anneleen Peeters

    Hey! I get this error and I don't know how to fix this. Can somebody help me with this? :)

    Circular reference detected for service "nexy_slack.client", path: "nexy_slack.client -> Nexy\Slack\Client -> nexy_slack.client".

    Thank you

  • 2020-02-11 weaverryan

    Hey Nick!

    Thanks for the comment :). Indeed, there is a bit going on with this library :/. Here are some details:

    1) If you download the course code and follow exactly, you won't have a problem. The problem is introduced in nexylan/slack-bundle 2.2.1, which requires Symfony 4.2.12. This tutorial uses Symfony 4.0, so it won't be installed.

    2) If you *are* running 4.2.12 or higher, you will get nexylan/slack-bundle 2.2.1 (or higher) which *does* appear to have some problems - specifically because that bundle requries nexylan/slack 3 (but 2.2.0 and lower require 2). The easiest way to fix this is to force version 2.2.0 of the bundle to be used in the tutorial:


    composer require nexylan/slack-bundle:2.2.0 php-http/guzzle6-adapter:1.1.1

    If you DO want to use the latest version of the bundle, I think you will need to install a few new packages - we actually talk about this exactly here: https://symfonycasts.com/sc...

    In your case Nick, I'm not sure why also adding nyholm/psr7 solved your problem. Honestly, this bundle relies on something called httplug, which makes the dependency issues a bit hard to follow. Anyways, we have some suggestions on how to get the latest version of the bundle working - in case nyholm/psr7 doesn't work for others.

    Cheers!

  • 2020-02-08 Nick

    for Symfony 4.4 you need to install these packages to make it work:

    composer require nexylan/slack-bundle php-http/guzzle6-adapter nyholm/psr7

  • 2020-01-23 Victor Bocharsky

    Hey Karin,

    Happy to hear it works for you now! You're welcome ;) But yeah, that bundle probably do need a recipe that will create that file for you. I even noticed an issue about it there: https://github.com/nexylan/...

    Cheers!

  • 2020-01-22 Karin Westerbeek

    My nexy_slack.yaml was directly under config. I moved it to config/packages and now it works!
    I was stuck on this soo long. Thanks.

  • 2020-01-22 Victor Bocharsky

    Hey Karin,

    In their docs: https://github.com/nexylan/... I see the "endpoint" option is required and because it does not have a recipe that will put that config for you - it fails. Btw, do you have any configuration for "nexy_slack"? I'd recommend you to try to create a config/packages/nexy_slack.yaml first, paste there a correct "endpoint" URL and then try to install the bundle again with:

    $ composer require nexylan/slack-bundle php-http/guzzle6-adapter:1.1.1

    This should help, at least it should not revert composer.json. Let me know if it still does not work for you.

    Cheers!

  • 2020-01-22 Karin Westerbeek

    I cannot get the nexylan slack bundle installed. My flex is up to date, I'm not on symfony 5.
    This is what happens:


    D:\Programming\4-2>composer require nexylan/slack-bundle php-http/guzzle6-adapter:1.1.1
    Using version ^2.2 for nexylan/slack-bundle
    ./composer.json has been updated
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
    Package operations: 19 installs, 0 updates, 0 removals
    - Installing symfony/options-resolver (v4.4.3): Loading from cache
    - Installing psr/http-message (1.0.1): Loading from cache
    - Installing clue/stream-filter (v1.4.1): Loading from cache
    - Installing php-http/message-factory (v1.0.2): Loading from cache
    - Installing php-http/message (1.8.0): Loading from cache
    - Installing php-http/promise (v1.0.0): Loading from cache
    - Installing php-http/httplug (v1.1.0): Loading from cache
    - Installing php-http/client-common (1.10.0): Loading from cache
    - Installing php-http/stopwatch-plugin (1.3.0): Loading from cache
    - Installing php-http/logger-plugin (1.1.0): Loading from cache
    - Installing php-http/discovery (1.7.4): Loading from cache
    - Installing ralouphie/getallheaders (3.0.3): Loading from cache
    - Installing guzzlehttp/psr7 (1.6.1): Loading from cache
    - Installing guzzlehttp/promises (v1.3.1): Loading from cache
    - Installing guzzlehttp/guzzle (6.5.2): Loading from cache
    - Installing php-http/guzzle6-adapter (v1.1.1): Loading from cache
    - Installing php-http/httplug-bundle (1.15.2): Loading from cache
    - Installing nexylan/slack (v2.3.0): Loading from cache
    - Installing nexylan/slack-bundle (v2.2.0): Loading from cache
    Writing lock file
    Generating autoload files
    Symfony operations: 2 recipes (04152d6cda7d8a7ea54d39ddeeebe7ca)
    - WARNING php-http/httplug-bundle (>=1.6): From github.com/symfony/recipes-contrib:master
    The recipe for this package comes from the "contrib" repository, which is open to community contributions.
    Review the recipe at https://github.com/symfony/recipes-contrib/tree/master/php-http/httplug-bundle/1.6

    Do you want to execute this recipe?
    [y] Yes
    [n] No
    [a] Yes for all packages, only for the current installation session
    [p] Yes permanently, never ask again for this project
    (defaults to n): a
    - Configuring php-http/httplug-bundle (>=1.6): From github.com/symfony/recipes-contrib:master
    - Configuring nexylan/slack-bundle (>=v2.2.0): From auto-generated recipe
    Executing script cache:clear [KO]
    [KO]
    Script cache:clear returned with error code 1
    !!
    !! In ArrayNode.php line 224:
    !!
    !! The child node "endpoint" at path "nexy_slack" must be configured.
    !!
    !!
    !!
    Script @auto-scripts was called via post-update-cmd

    Installation failed, reverting ./composer.json to its original content.

    They're both added to bundles.php, but not to composer.json. Anytime I do anything in the terminal (cache:clear, debug:autowiring, whatever) it keeps telling me In ArrayNode.php line 224: The child node "endpoint" at path "nexy_slack" must be configured.
    Even though I created the nexy_slack.yaml with the required endpoint:


    nexy_slack:
    # The Slack API Incoming WebHooks URL.
    endpoint: 'http://hooks.slack.com/services/****'

    Can I just continue with the course without nexylan/slack or do I need it in further chapters?

  • 2020-01-20 weaverryan

    Hey John!

    Sorry for my slow reply! If you installed the wrong bundle - e.g. with composer require some/bundle-name then you can uninstall it the same way, replacing require with remove: composer remove some/bundle-name. When you uninstall a package/bundle, the recipe will "uninstall" itself, which will remove any config, etc that was added when the bundle was installed.

    Let me know if this helps!

    Cheers!

  • 2020-01-15 John

    How am I able to remove a bundle ?
    Didn't find anything about this, if i for example installed the wrong one

  • 2020-01-09 Diego Aguiar

    > Nothing to install or update
    That makes me think you already have Flex installed but not for the latest version. Maybe if you run compser update symfony/flex?

    Also, try requiring Flex by project basis and not globally

    Cheers!

  • 2020-01-09 DannyR

    Hey Diego,

    I think I'm trying the suggested solution, here's what happens:

    APFVFXJ2F7HV2H:~ roushd$ composer global require symfony/flex ^1.5
    Changed current directory to /Users/roushd/.composer
    ./composer.json has been updated
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
    Nothing to install or update
    Generating autoload files
    Symfony recipes are disabled: "symfony/flex" not found in the root composer.json

  • 2020-01-03 Diego Aguiar

    Hey DannyR

    I think you hit the same problem as mentioned in this thread https://github.com/symfony/...
    The fix is to upgrade Symfony Flex (global installation as well in case you have it). Could you give it a try and let me know if it worked?

    Cheers!

  • 2020-01-03 Victor Bocharsky

    Hey John,

    From the output I see the problem is in "nexylan/slack-bundle" - it's not ready for Symfony 5 yet. Though, I noticed an opened PR about Symfony 5 support, see https://github.com/nexylan/... - untill this one is merged - no way to install this bundle on Symfony 5, it can be installed on Symfony 4 only. If you want, you could give a code review of that PR, it might push it forward.

    Cheers!

  • 2020-01-03 John

    Is there a way to get this working in Symfony 5 ?
    In Terminal: composer require nexylan/slack-bundle:* php-http/guzzle6-adapter:*
    I got the error message, when requiring the bundle:

    Problem 1
    - nexylan/slack-bundle v2.2.0 requires symfony/http-kernel ^3.4 || ^4.0 -> no matching package found.
    - nexylan/slack-bundle v2.1.0 requires symfony/http-kernel ^3.4 || ^4.0 -> no matching package found.
    - nexylan/slack-bundle v2.0.1 requires symfony/http-kernel ^3.4 || ^4.0 -> no matching package found.
    - nexylan/slack-bundle v2.0.0 requires symfony/http-kernel ^3.4 || ^4.0 -> no matching package found.
    - nexylan/slack-bundle v1.1.2 requires symfony/http-kernel ^2.7 || ^3.0 || ^4.0 -> no matching package found.
    - nexylan/slack-bundle v1.1.1 requires symfony/http-kernel ^2.7 || ^3.0 -> no matching package found.
    - nexylan/slack-bundle v1.1.0 requires symfony/http-kernel ^2.7 || ^3.0 -> no matching package foun.
    - nexylan/slack-bundle v1.0.1 requires symfony/http-kernel ^2.7 || ^3.0 -> no matching package found
    - nexylan/slack-bundle v1.0.0 requires symfony/http-kernel ^2.8 || ^3.0 -> no matching package found.
    - Installation request for nexylan/slack-bundle * -> satisfiable by nexylan/slack-bundle[v1.0.0, v1.0.1, v1.1.0, v1.1.1, v1.1.2, v2.0.0, v2.0.1, v2.1.0, v2.2.0].

    Installation failed, reverting ./composer.json to its original content.

  • 2019-12-30 DannyR

    When I run: $ composer require nexylan/slack-bundle php-http/guzzle6-adapter:1.1.1

    I get . . .

    [ErrorException]
    curl_multi_setopt(): CURLPIPE_HTTP1 is no longer supported

  • 2019-07-31 Victor Bocharsky

    Hey Pedro,

    Thank you for sharing this info with others! Though, it's weird, because in the screencast we see bundles were added automatically. Do you use symfony Flex in your project? What version of Symfony do you use? Anyway, adding it manually should work, thanks for this tip, might be useful for people who see the same error message.

    Cheers!

  • 2019-07-30 Pedro Cambra

    As mentioned below, running the install as recommended did not get the bundle added to bundles.php or the httplug.yaml file created, I had to add them manually.

    The error I got is " The service "nexy_slack.client" has a dependency on a non-existent service "httplug.client". "

  • 2018-12-12 Mark Onofrio

    This also worked for me! Thanks!

  • 2018-11-29 Vladimir Sadicov

    Hey Patrick!

    It's awesome that you have found a working solution for this issue. We have checked packages and found that updated `php-http/guzzle6-adapter` caused it. Probably better solution will be to use

    composer require nexylan/slack-bundle php-http/guzzle6-adapter:1.1.1

    it will be closer to course code.

    By the way we have already updated course page with this new command.

    Cheers!.

  • 2018-11-27 Ahmed Ayman

    probably a different version of composer. or a newer release of php-http that is conflicting with the nexylan bundle. idk!

  • 2018-11-27 Ahmed Ayman

    and got it working by adding :
    "nexylan/slack-bundle": "*",
    "php-http/guzzle6-adapter":"*",
    in the require part of the composer.json file

  • 2018-11-27 Patrick Cool

    I got it 'working' with
    composer require nexylan/slack-bundle:1.1.2 php-http/guzzle6-adapter
    'working' means getting the same error as in the tutorial

    Unfortunately Http\HttplugBundle\HttplugBundle::class => ['all' => true], is not added to config/bundles.php and the file confgi/packages/httplug.yaml was not created either.
    I do find however httplug in vendor/php-http/ and the composer require mentioned that it was installed

    omposer require nexylan/slack-bundle:1.1.2 php-http/guzzle6-adapter
    Using version ^2.0 for php-http/guzzle6-adapter
    ./composer.json has been updated
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
    Restricting packages listed in "symfony/symfony" to "4.1.*"

    Prefetching 6 packages 🎵 💨
    - Downloading (100%)

    Package operations: 10 installs, 0 updates, 0 removals
    - Installing guzzlehttp/promises (v1.3.1): Loading from cache
    - Installing psr/http-message (1.0.1): Loading from cache
    - Installing guzzlehttp/psr7 (1.4.2): Loading from cache
    - Installing guzzlehttp/guzzle (6.3.3): Loading from cache
    - Installing nexylan/slack (1.7.0): Loading from cache
    - Installing nexylan/slack-bundle (v1.1.2): Loading from cache
    - Installing psr/http-client (1.0.0): Loading from cache
    - Installing php-http/promise (v1.0.0): Loading from cache
    - Installing php-http/httplug (v2.0.0): Loading from cache
    - Installing php-http/guzzle6-adapter (v2.0.0): Loading from cache
    Writing lock file
    Generating autoload files
    Symfony operations: 1 recipe (1419766d96901a70366acb1ed9be6db3)
    - Configuring nexylan/slack-bundle (>=v1.1.2): From auto-generated recipe
    Executing script cache:clear [KO]
    [KO]
    Script cache:clear returned with error code 1
    !!
    !! In ArrayNode.php line 228:
    !!
    !! The child node "endpoint" at path "nexy_slack" must be configured.
    !!
    !!
    !!
    Script @auto-scripts was called via post-update-cmd

  • 2018-11-26 Patrick

    I got it 'working' with
    composer require nexylan/slack-bundle:1.1.2 php-http/guzzle6-adapter

    'working' means getting the same error as in the tutorial

  • 2018-11-26 Patrick

    thanks for your reply. Don't understand why in the tutorial this error did not happen

  • 2018-11-26 Diego Aguiar

    Hmm, nexylan/slack-bundle requires php-http/httplug v1.1 but php-http/guzzle6-adapter requires php-http/httplug v2.0 so you can't have both versions installed, you need to find a release where both bundle versions can work together, you may want to contact the repository maintainer.

    Cheers!

  • 2018-11-26 Patrick

    using Symfony 4.1.7 I get the following error after
    composer require nexylan/slack-bundle php-http/guzzle6-adapter

    Using version ^2.0 for nexylan/slack-bundle
    Using version ^2.0 for php-http/guzzle6-adapter
    ./composer.json has been updated
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
    Restricting packages listed in "symfony/symfony" to "4.1.*"
    Your requirements could not be resolved to an installable set of packages.

    Problem 1
    - Installation request for nexylan/slack-bundle ^2.0 -> satisfiable by nexylan/slack-bundle[v2.0.0].
    - nexylan/slack v2.0.0 requires php-http/client-common ^1.7 -> satisfiable by php-http/client-common[1.7.0, 1.8.0, 1.8.1].
    - php-http/client-common 1.7.0 requires php-http/httplug ^1.1 -> satisfiable by php-http/httplug[v1.1.0].
    - php-http/client-common 1.8.0 requires php-http/httplug ^1.1 -> satisfiable by php-http/httplug[v1.1.0].
    - php-http/client-common 1.8.1 requires php-http/httplug ^1.1 -> satisfiable by php-http/httplug[v1.1.0].
    - Can only install one of: php-http/httplug[v2.0.0, v1.1.0].
    - php-http/guzzle6-adapter v2.0.0 requires php-http/httplug ^2.0 -> satisfiable by php-http/httplug[v2.0.0].
    - nexylan/slack-bundle v2.0.0 requires nexylan/slack ^2.0 -> satisfiable by nexylan/slack[v2.0.0].
    - Installation request for php-http/guzzle6-adapter ^2.0 -> satisfiable by php-http/guzzle6-adapter[v2.0.0].

    Installation failed, reverting ./composer.json to its original content.

  • 2018-06-14 toporovvv

    If you need second dev channel to work on other instance of your application (like prod slack channel - for prod environment, dev slack channel - for developers environment), than you need to specify endpoint as a parameter like
    endpoint: '%slackEndpoint%'
    and then specify this parameters in services.yaml and services_dev.yaml as it was done in the past tutorial of this course (https://knpuniversity.com/s....

  • 2018-06-07 Babagana Zannah

    Thank you so so very much Sir. Thank you.

  • 2018-06-07 weaverryan

    Hi Babagana Zannah!

    Hmm. First, I may give a silly answer, because I'm trying to remember how this bundle works :). And, actually, the way the the incoming webhooks work is confusing. So, when you setup the webhook in Slack, you configure which channel you want to send to. But, when you actually *send* the message in PHP, there is also a to() method where you can set the channel: https://github.com/nexylan/...

    So, I would try using this ONE endpoint and the to() method to try to send to the #dev channel. From my reading, it sounds like this may *not* work - but I'm not 100% sure... because it seems odd to have this to() method, if it never works. If it doesn't work and you DO need 2 endpoints then, yes, the bundle does not support this. It's not a HUGE deal, you will just need to configure a second "Nexy\Slack\Client" service manually on your own (i.e. in services.yml).

    Cheers!

  • 2018-06-07 Babagana Zannah

    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?