PHPackages                             tatarko/yii-slack - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. tatarko/yii-slack

ActiveLibrary[API Development](/categories/api)

tatarko/yii-slack
=================

Yii extension for accessing Slack API with Guzzle interface

v0.4.1(11y ago)330.8kMITPHP

Since Mar 22Pushed 11y ago1 watchersCompare

[ Source](https://github.com/tatarko/yii-slack)[ Packagist](https://packagist.org/packages/tatarko/yii-slack)[ RSS](/packages/tatarko-yii-slack/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (2)Versions (7)Used By (0)

Yii Slack extension
===================

[](#yii-slack-extension)

Yii extension for accessing Slack API in Yii framework via Guzzle.

[![Latest Stable Version](https://camo.githubusercontent.com/756c4e16e7ca27c38e250fcc26801681b789a9dde232692354e6e320f27c59b1/68747470733a2f2f706f7365722e707567782e6f72672f74617461726b6f2f7969692d736c61636b2f762f737461626c652e706e67)](https://packagist.org/packages/tatarko/yii-slack)[![Code Climate](https://camo.githubusercontent.com/e898387f223130ce66f5e839b69582645210b0ceff69c666dbbf8e4bb6d68620/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f74617461726b6f2f7969692d736c61636b2f6261646765732f6770612e706e67)](https://codeclimate.com/github/tatarko/yii-slack)

Installation
------------

[](#installation)

**Yii Slack** is composer library so you can install the latest version with:

```
php composer.phar require tatarko/yii-slack
```

Configuration
-------------

[](#configuration)

To your application's config add following:

```
'components' => array(
	'slack' => array(
		'class' => 'Tatarko\\YiiSlack\\ApplicationComponent',
		'appId' => '', // Your's application ID
		'appSecret' => '', // Your's application secret code
		'tokenStateName' => 'slack.access.token'; // optional - change name of the user's state variable to store access token in
		'companyToken' => '', // optional - set global access token of your company's account to use slack component without user authentication
	),
)
```

For OAuth authentication add following method to the controller:

```
class SiteController extends Controller
{
	public function actions()
    {
        return array(
            'slack' => array(
                'class' => 'Tatarko\\YiiSlack\\AuthenticationAction',
				'onAuthSuccess' => function(CEvent $event) {
					// you can get $event->params->access_token and store it in some persistant database instead of user's states (that is basically sessions variable)
					$this->redirect('welcome');
				},
                'onAuthError' => function(CEvent $event) {
					// $event->params is instance of Exception (CException or GuzzleHttp\Exception\TransferException)
					$this->redirect('login');
				},
            ),
        );
    }
}
```

Usage
-----

[](#usage)

For simple OAuth just create link in any view file:

```
