SlackBuu is a Slack Bot User Underlayer written in PHP. It can be used as a library or base code to develop a chat bot on Slack from.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
WebSocket
logs
www
Config.php
LICENSE
README.md
SlackBotUser.php
start-dev.php
start-prod.php

README.md

SlackBuu

What is SlackBuu?

SlackBuu is Slack Bot User Underlayer.

It is a PHP library for building Slack chat bot apps on top of.

It does not try to make use of every type of custom integration in Slack. It is specifically made to build Slack chat bot services, one that connects to Slack's WebSockets API and send & receive messages.

Additionally, this also includes the OAuth logic for users to add your app onto their Slack team. (Optional)

The motivation to develop this comes from the fact that while many good libraries for Slack integration are available in other langauges, the selection for PHP is more limited. There are a few out there that have very heavy dependencies, like React PHP, or PHP 5.4+ / 5.5+. (At this moment, PHP 5.3 is still the default version that comes with many AWS and Digital Ocean builds, which makes having a PHP 5.4+ requirement a laborous effort to deploy something quickly to play around with.)

Requirements

  • PHP 5.3 or above
  • PHP cURL library
  • PHP POSIX library (php-posix or php-process)
  • Apache web server (Optional, only if you want the OAuth integration)
  • No other dependencies, so composer not required; since everything needed is included in the repo.

Credits

Because I'm not using composer dependencies, I included in this repo two PHP libraries I made use of:

  • Websocket-PHP to allow a PHP script to act as a WebSocket client (not server)
  • ToroPHP to make clean URLs easily in a very light-weight way

Slack APIs used

This library makes use of the following Slack APIs:

Getting started

You can use only the SlackBotUser module on its own, as a PHP chat bot server just for your Slack team as custom integration; or you can use the OAuth layer in addition, which will be a full base code for building your own distributable Slack app.

To start a bot user on your Slack team only

  1. Visit https://[yourteam].slack.com/apps/manage/A0F7YS25R-bots
  2. Click "Add integration", choose a name, and copy the API token of the bot.
  3. Cd to the root of this repo, and use the API token in the following command.
  4. Run php start-dev.php xoxb-123-abc and your chat bot will start running!

To build a distributable Slack chat bot app

  1. Run chmod 777 logs to make the logs directory writable and executable by Apache.
  2. Set up a vhost on your domain and dev domain.
  3. Look at www/index.php to see how prod and dev environment is determined. Set up your vhost accordingly.
  4. Create a new Slack app from this page.
  5. Enter something for App Name, Team, Description, Icon, etc.
  6. In the "Redirect URI(s)" field, enter your domain. For example: http://yourdomain.com/
  7. Copy the Client ID and Client Secret from the result page, paste into Config.php accordingly, and update the host name in there.
  8. Scroll down on this page, to "Bot User", click "Add a bot to this app".
  9. Pick a name and click the "Add bot user" button.
  10. Visit http://yourdomain.com and install your own app and try it out!

License

SlackBuu was created by Bigi Lui and released under the MIT License.