fintech-systems / slack-php-api
A Laravel friendly PHP API designed to ease interfacing with Slack
v0.0.6
2021-11-13 09:10 UTC
Requires
- fintech-systems/laravel-api-helpers: ^0.1.2
- monolog/monolog: ^2.3
- spatie/ray: ^1.30
- symfony/dotenv: ^5.3
Requires (Dev)
- guzzlehttp/guzzle: ^7.0
- orchestra/testbench: ^6.20
- pestphp/pest: ^1.20
README
A Slack API designed to run standalone or as part of a Laravel Application
Requirements:
- PHP 8.0
- A Slack App
Usage
References
- https://www.tyntec.com/docs/whatsapp-business-api-integration-slack -- Description on setting up the Slack Bot Token
- https://api.slack.com/methods/chat.postMessage -- Description on how to set up the Slack User Token
- Difference bot and user tokens? -- https://api.slack.com/authentication/token-types#user --- xoxp = user token, xoxb = bot token
Framework Agnostic PHP
<?php use FintechSystems\Slack\Slack; require 'vendor/autoload.php'; $dotenv = Dotenv\Dotenv::createImmutable(__DIR__); $dotenv->load(); $server = [ 'bot_token' => $_ENV['SLACK_BOT_TOKEN'], 'user_token' => $_ENV['SLACK_USER_TOKEN'], 'channel' => $_ENV['SLACK_CHANNEL'], ]; $api = new Slack($server);
Laravel Installation
You can publish the config file with:
php artisan vendor:publish --provider="FintechSystems\Slack\SlackServiceProvider" --tag="slack-config"
This is the contents of the published config file:
This is the contents of the published config file:
return [ 'bot_token' => env('SLACK_BOT_TOKEN'), 'user_token' => env('SLACK_USER_TOKEN'), 'channel' => env('SLACK_CHANNEL'), ];
Usage
Example
use FintechSystems\LaravelApiHelpers\Api; $api = new Api(); $postData = [ 'channel' => 'C02G5QS8ANA', 'text' => '*Joe Smith*/27823096710: how are you', 'thread_ts' => '1635100445.007500', ]; $result = $api->postMessage($postData);
Methods
public function postMessage(String $postFields) public function makeImagePublic($id) public function reconstructImageUrl($filesZero)
Testing
vendor/bin/pest
Local Development
If you are debugging from another package on localhost, then add this to composer.json
:
"repositories" : [ { "type": "path", "url": "../slack-php-api" } ]
Then in require
section:
"fintech-systems/slack-php-api": "dev-main",
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Feel free to log an issue or create a pull request.
Credits
License
The MIT License (MIT). Please see License File for more information.