All Projects → sagebind → Slack Client

sagebind / Slack Client

Licence: mit
A better Slack client, with RTM API support.

Projects that are alternatives of or similar to Slack Client

Aioquant
Asynchronous event I/O driven quantitative trading framework.
Stars: ✭ 188 (-4.08%)
Mutual labels:  async
Actix Extras
A collection of additional crates supporting the actix and actix-web frameworks.
Stars: ✭ 190 (-3.06%)
Mutual labels:  async
Fooproxy
稳健高效的评分制-针对性- IP代理池 + API服务,可以自己插入采集器进行代理IP的爬取,针对你的爬虫的一个或多个目标网站分别生成有效的IP代理数据库,支持MongoDB 4.0 使用 Python3.7(Scored IP proxy pool ,customise proxy data crawler can be added anytime)
Stars: ✭ 195 (-0.51%)
Mutual labels:  async
Go Sarah
Simple yet customizable bot framework written in Go.
Stars: ✭ 188 (-4.08%)
Mutual labels:  slack
Vim Signify
➕ Show a diff using Vim its sign column.
Stars: ✭ 2,390 (+1119.39%)
Mutual labels:  async
Diffadapter
A high-performance , easy-to-use Adapter for RecyclerView ,using diffutil
Stars: ✭ 193 (-1.53%)
Mutual labels:  async
Activej
ActiveJ is an alternative Java platform built from the ground up. ActiveJ redefines web, high load, and cloud programming in Java, featuring ultimate performance and scalability!
Stars: ✭ 183 (-6.63%)
Mutual labels:  async
Gmqtt
Python MQTT v5.0 async client
Stars: ✭ 195 (-0.51%)
Mutual labels:  async
Ppipe
pipes values through functions, an alternative to using the proposed pipe operator ( |> ) for ES
Stars: ✭ 192 (-2.04%)
Mutual labels:  async
Bolt Python
A framework to build Slack apps using Python
Stars: ✭ 190 (-3.06%)
Mutual labels:  slack
Vkbottle
Homogenic! Customizable asynchronous VK API framework
Stars: ✭ 191 (-2.55%)
Mutual labels:  async
Thirtyfour
Selenium WebDriver client for Rust, for automated testing of websites
Stars: ✭ 191 (-2.55%)
Mutual labels:  async
Unfurl
Scraper for oEmbed, Twitter Cards and Open Graph metadata - fast and Promise-based ⚡️
Stars: ✭ 193 (-1.53%)
Mutual labels:  slack
Jsx Slack
Build JSON object for Slack Block Kit surfaces from JSX
Stars: ✭ 188 (-4.08%)
Mutual labels:  slack
Trilogy
TypeScript SQLite layer with support for both native C++ & pure JavaScript drivers.
Stars: ✭ 195 (-0.51%)
Mutual labels:  async
Iguazu
✨ Iguazu is a simple Redux-powered Async Query engine
Stars: ✭ 186 (-5.1%)
Mutual labels:  async
Use Async Effect
🏃 Asynchronous side effects, without the nonsense
Stars: ✭ 193 (-1.53%)
Mutual labels:  async
Paper
Hassle-free HTML to PDF conversion abstraction library.
Stars: ✭ 196 (+0%)
Mutual labels:  async
Ok ip proxy pool
🍿爬虫代理IP池(proxy pool) python🍟一个还ok的IP代理池
Stars: ✭ 196 (+0%)
Mutual labels:  async
Stripe
Typed .NET clients for stripe.com REST APIs
Stars: ✭ 193 (-1.53%)
Mutual labels:  async

PHP Slack API Client

Build Version License Code Coverage Code Quality Downloads

This is an API client for Slack for PHP clients, with support for the Real Time Messaging API (RTM API) using web sockets.

Project status

This project is based on some outdated and unmaintained libraries, and itself is not being actively maintained.

Overview

This library was created primarily for Slackyboy, but was branched off into its own codebase so it could be used in other projects as well. I created this client because existing clients were either too complicated to use, or buggy, or incomplete. This is also the first PHP client I am aware of to support Slack's RTM API.

Installation

Install with Composer, obviously:

$ composer require coderstephen/slack-client

Please note that the current version has unstable dependencies.

In order to install those dependencies, you can set "minimum-stability" in your composer.json, and recommend that you set "prefer-stable":

{
    "minimum-stability": "dev",
    "prefer-stable": true
}

Usage

First, you need to create a client object to connect to the Slack servers. You will need to acquire an API token for your app first from Slack, then pass the token to the client object for logging in. Since this library uses React, you must also pass in an event loop object:

$loop = \React\EventLoop\Factory::create();

$client = new \Slack\ApiClient($loop);
$client->setToken('YOUR-TOKEN-HERE');
// ...
$loop->run();

Assuming your token is valid, you are good to go! You can now use wrapper methods for accessing most of the Slack API. Below is an example of posting a message to a channel as the logged in user:

$client->getChannelById('C025YTX9D')->then(function (\Slack\Channel $channel) use ($client) {
    $client->send('Hello from PHP!', $channel);
});

Advanced messages

Slack supports messages much more rich than plain text through attachments. The easiest way to create a custom message is with a MessageBuilder:

use Slack\Message\{Attachment, AttachmentBuilder, AttachmentField};

$message = $client->getMessageBuilder()
    ->setText('Hello, all!')
    ->setChannel($someChannelObject)
    ->addAttachment(new Attachment('My Attachment', 'attachment text'))
    ->addAttachment(new Attachment('Build Status', 'Build failed! :/', 'build failed', 'danger'))
    ->addAttachment(new AttachmentBuilder()
        ->setTitle('Some Fields')
        ->setText('fields')
        ->setColor('#BADA55')
        ->addField(new AttachmentField('Title1', 'Text', false))
        ->addField(new AttachmentField('Title2', 'Some other text', true))
        ->create()
    ]))
    ->create();

$client->postMessage($message);

Check the API documentation for a list of all methods and properties that messages, attachments, and fields support.

Asynchronous requests and promises

All client requests are made asynchronous using React promises. As a result, most of the client methods return promises. This lets you easily compose request orders and handle them as you need them. Since it uses React, be sure to call $loop->run() or none of the requests will be sent.

React allows the client to perform well and prevent blocking the entire thread while making requests. This is especially useful when writing real-time apps, like Slack chat bots.

Real Time Messaging API

You can also connect to Slack using the Real Time Messaging API. This is often useful for creating Slack bots or message clients. The real-time client is like the regular client, but it enables real-time incoming events. First, you need to create the client:

$client = new \Slack\RealTimeClient();
$client->setToken('YOUR-TOKEN-HERE');
$client->connect();

Then you can use the client as normal; RealTimeClient extends ApiClient, and has the same API for sending requests. You can attach a callback to handle incoming Slack events using RealTimeClient::on():

$client->on('file_created', function($data) {
    echo 'A file was created called ' . $data['file']['name'] . '!\n';
});

Below is a very simple, complete example:

$loop = React\EventLoop\Factory::create();

$client = new Slack\RealTimeClient($loop);
$client->setToken('YOUR-TOKEN-HERE');

// disconnect after first message
$client->on('message', function ($data) use ($client) {
    echo "Someone typed a message: ".$data['text']."\n";
    $client->disconnect();
});

$client->connect()->then(function () {
    echo "Connected!\n";
});

$loop->run();

See the Slack API documentation for a list of possible events.

Documentation

You can view the complete API documentation here.

Running tests

You can run automated unit tests using PHPUnit after installing dependencies:

$ vendor/bin/phpunit

Where to get help

Need help? Just send me an email with your questions. Be sure to add "Slack client" to the message subject line so I know how I can help you out.

License

This library is licensed under the MIT license. See the LICENSE file for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].