insidieux / slack-api
Simple Slack API client wih predefined methods
Installs: 26 260
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 2
Open Issues: 4
Requires
- php: >=5.5.0
- ext-curl: *
- ext-json: *
Requires (Dev)
- codacy/coverage: dev-master
- codeclimate/php-test-reporter: dev-master
- phpunit/phpunit: 4.*
- squizlabs/php_codesniffer: ~2.3
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 |
---|
A simple PHP package for making request to Slack API, focused on ease-of-use and elegant syntax.
Requirements
- PHP 5.5 or greater
- CURL extension for PHP
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:
- [channels] (https://api.slack.com/methods#channels)
- [chat] (https://api.slack.com/methods#chat)
- [dnd] (https://api.slack.com/methods#dnd)
- [emoji] (https://api.slack.com/methods#emoji)
- [files] (https://api.slack.com/methods#files)
- [groups] (https://api.slack.com/methods#groups)
- [im] (https://api.slack.com/methods#im)
- [oauth] (https://api.slack.com/methods#oauth)
- [pins] (https://api.slack.com/methods#pins)
- [search] (https://api.slack.com/methods#search)
- [team] (https://api.slack.com/methods#team)
- [usergroups] (https://api.slack.com/methods#usergroups)
- [users] (https://api.slack.com/methods#users)
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()