A Slack API designed to run standalone or as part of a Laravel Application
Requirements:
- PHP 8.0
- A Slack App
- 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
<?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);
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'),
];
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);
public function postMessage(String $postFields)
public function makeImagePublic($id)
public function reconstructImageUrl($filesZero)
vendor/bin/pest
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",
Please see CHANGELOG for more information on what has changed recently.
Feel free to log an issue or create a pull request.
The MIT License (MIT). Please see License File for more information.