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

This package is auto-updated.

Last update: 2024-10-13 16:19:42 UTC


README

GitHub release (latest by date) Build Status GitHub

A Slack API designed to run standalone or as part of a Laravel Application

Requirements:

  • PHP 8.0
  • A Slack App

Usage

References

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.