insidieux/slack-api

This package is abandoned and no longer maintained. No replacement package was suggested.

Simple Slack API client wih predefined methods

1.4.2 2021-02-08 12:38 UTC

This package is auto-updated.

Last update: 2023-02-27 22:35:30 UTC


README

This project is very outdated and behind the current actual version of php, as well as the current version of the Slack API. We strongly DO NOT RECOMMEND you to use this library and we advise you to switch to one of the published packages from the official Slack documentation - https://api.slack.com/community#php

Build Status Code Climate Test Coverage Codacy Badge Codacy Badge

A simple PHP package for making request to Slack API, focused on ease-of-use and elegant syntax.

Requirements

Installation

You can install the package using the Composer package manager. You can install it by running this command in your project root:

composer require insidieux/slack-api

Usage

Create API client

$client = new \SlackApi\Client('your-token-here');

Make request

$client = new \SlackApi\Client('your-token-here');
$response = $client->request('module.method', ['argument' => 'value']);
$response->toArray();

Or you can use predefined modules and methods

$client = new \SlackApi\Client('your-token-here');
$response = $client->users()->getList();
$response->toArray()

Predefined modules:

Message and attachment objects

Create message object

$client = new \SlackApi\Client('your-token-here');
$message = new \SlackApi\Models\Message($client);

or

$client = new \SlackApi\Client('your-token-here');
$message = $client->makeMessage();

Create new attachment from array

$data = [
    'fallback' => 'Some fallback'
    'pretext'  => 'Some pretext',
    'text'     => 'good',
    'text'     => 'Some text'
]; 
$attachment1 = new \SlackApi\Models\Attachment($data);

Or use set methods

$attachment2 = new \SlackApi\Models\Attachment;
$attachment2->setText('Some text')
    ->setColor(\SlackApi\Models\Attachment::COLOR_GOOD)
    ->setFallback('Some fallback');

Add field to attachment

$field = new \SlackApi\Models\AttachmentField;
$field->setShort(false)
    ->setTitle('Field title')
    ->setValue('Field value');
$attachment->addField($field);

Attach object to message

$message->attach($attachment);

Send message

$response = $message->send();
$response->toArray()

Author