Download the PHP package slack-php/slack-app-framework without Composer
On this page you can find all versions of the php package slack-php/slack-app-framework. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download slack-php/slack-app-framework
More information about slack-php/slack-app-framework
Files in slack-php/slack-app-framework
Package slack-app-framework
Short Description Provides a foundation upon which to build a Slack application in PHP
License MIT
Informations about the package slack-app-framework
Slack App Framework for PHP
By Jeremy Lindblom (@jeremeamia)
Introduction
A PHP framework for building Slack apps. It takes inspiration from Slack's Bolt frameworks.
If you are new to Slack app development, you will want to learn about it on Slack's website. This library is only useful if you already understand the basics of building Slack applications.
Installation
- Requires PHP 7.4+
- Use Composer to install:
composer require slack-php/slack-app-framework
General Usage
Quick Warning
This library has been heavily dogfooded, but the project is severely lacking in test coverage and documentation, so use it at your own risk, as the MIT license advises.
- Contributions welcome (especially for documentation and tests).
- For questions, feedback, suggestions, etc., use Discussions.
- For issues or concerns, use Issues.
Development Patterns
When creating an app, you can configure your app from the Slack website. The framework is designed to recieve requests from all of your app's interaction points, so you should configure all of the URLs (e.g., in Slash Commands, Interactivity & Shortcuts (don't forget the Select Menus section), and Event Subscriptions) to point to the root URL of your deployed app code.
When developing the app code, you declare one or more Listener
s using the App
's routing methods that correspond to
the different types of app interaction. Listener
s can be declared as closures, or as objects and class names of type
SlackPhp\Framework\Listener
. A Listener
receives a Context
object, which contains the payload data provided by
Slack to the app and provides methods for all the actions you can take to interact with or communicate back to Slack.
Quick Example
This small app responds to the /cool
slash command.
Assumptions:
- You have required the Composer autoloader to enable autoloading of the framework files.
- You have set
SLACK_SIGNING_KEY
in the environment (e.g.,putenv("SLACK_SIGNING_KEY=foo");
)
Example Application
The "Hello World" app says hello to you, by utilizing every type of app interactions, including: slash commands, block actions, block suggestions (i.e., options for menus), shortcuts (both global and message level), modals, events, and the app home page.
"Hello World" app code
> Assumptions: > > - You have required the Composer autoloader to enable autoloading of the framework files. > - You have set `SLACK_SIGNING_KEY` in the environment (e.g., `putenv("SLACK_SIGNING_KEY=foo");`) > - You have set `SLACK_BOT_TOKEN` in the environment (e.g., `putenv("SLACK_BOT_TOKEN=bar");`)Object-Oriented Version
You can alternatively create your App and Listeners as a set of classes. I recommend this approach if you have more than a few listeners or if your listeners are complicated. Here is an example of how the "Hello World" app would look when developed in this way.
"Hello World" app code
`App.php` `index.php` > Assumptions: > > - You have required the Composer autoloader to enable autoloading of the framework files. > - You have configured composer.json so that your `MyApp` namespaced code is autoloaded. > - You have set `SLACK_SIGNING_KEY` in the environment (e.g., `putenv("SLACK_SIGNING_KEY=foo");`) > - You have set `SLACK_BOT_TOKEN` in the environment (e.g., `putenv("SLACK_BOT_TOKEN=bar");`)Handling Requests with the Context
Object
The Context
object is the main point of interaction between your app and Slack. Here are all the things you can do
with the Context
:
High Level Design
YUML Source
[AppServer]<>-runs>[App] [AppServer]creates->[Context] [App]<>->[AppConfig] [App]<>->[Router] [Router]-^[Listener] [Router]<>1-*>[Listener] [Listener]handles->[Context] [Context]<>->[Payload] [Context]<>->[AppConfig] [Context]<>->[_Clients_;RespondClient;ApiClient] [Context]<>->[_Helpers_;BlockKit;Modals;View] [Context]<>->[_Metadata_] [AppConfig]<>->[Logger] [AppConfig]<>->[Container] [AppConfig]<>->[_Credentials_]
Socket Mode
Socket mode support is provided by a separate package. See slack-php/slack-php-socket-mode.
Not Implemented
The following features are known to be missing:
- OAuth flow for handling installations to a different workspace.
- Though there are some class in the
SlackPhp\Framework\Auth
namespace if you need to roll your own right now.
- Though there are some class in the
Standards Used
- PSR-1, PSR-12: Coding Style
- PSR-3: Logger Interface
- PSR-4: Autoloading
- PSR-7, PSR-15, PSR-17: HTTP
- PSR-11: Container Interface
All versions of slack-app-framework with dependencies
ext-ctype Version *
ext-json Version *
slack-php/slack-block-kit Version ^0.19.0 || ^1.0.0
nyholm/psr7 Version ^1.3
nyholm/psr7-server Version ^1.0
psr/container Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^1.0
psr/http-server-handler Version ^1.0
psr/http-server-middleware Version ^1.0
psr/log Version ^1.1