Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Slack連携 #43

Merged
merged 6 commits into from
May 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ OAUTH_ONLY=false
# Google Analytics関連
# scriptの埋め込みをする場合は、下の行をコメントから復旧させた後にIDを記述してください
# GA_TRACKING_ID=


# slackポスト設定
# SLACK_ENDPOINT=https://hooks.slack.com/services/access_token
# SLACK_USERNAME=slack_post_name
# SLACK_ICON=:slack_icon:
5 changes: 5 additions & 0 deletions .env.mysql.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ OAUTH_PROVIDER=null
OAUTH_CLIENT=your-oauth-client-id
OAUTH_SECRET=your-oauth-sercret
OAUTH_REDIRECT=your-oauth-callback-redirect

# slackポスト設定
# SLACK_ENDPOINT=https://hooks.slack.com/services/access_token
# SLACK_USERNAME=slack_post_name
# SLACK_ICON=:slack_icon:
5 changes: 5 additions & 0 deletions .env.sqlite.exmple
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ OAUTH_PROVIDER=null
OAUTH_CLIENT=your-oauth-client-id
OAUTH_SECRET=your-oauth-sercret
OAUTH_REDIRECT=your-oauth-callback-redirect

# slackポスト設定
# SLACK_ENDPOINT=https://hooks.slack.com/services/access_token
# SLACK_USERNAME=slack_post_name
# SLACK_ICON=:slack_icon:
8 changes: 8 additions & 0 deletions app/Http/Controllers/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
use Validator;
use Auth;
use DB;
use Config;
use App\Http\Requests;
use App\Article;
use App\ArticleTag;
use Illuminate\Http\Request;
use Maknz\Slack\Facades\Slack;


class ArticleController extends Controller
Expand Down Expand Up @@ -103,6 +105,12 @@ public function postOne(Request $request)
$article->save();
$request->session()->flash('flash_message', $message);
});
if($article->status === 'internal' && Config::get('slack.endpoint')){
// slackで告知
$title = $article->getAttributeValue('title');
$slack_message = "新しく記事が公開されました! 「".$title."」\r\n ". route('get_article_single', ['articleId' => $article->id]);
Slack::send($slack_message);
}
return redirect(route('get_article_single', ['articleId' => $article->id]));
}

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"laravel/socialite": "^2.0",
"cebe/markdown": "^1.1",
"laravelcollective/html": "^5.2",
"doctrine/dbal": "^2.5"
"doctrine/dbal": "^2.5",
"maknz/slack": "^1.7"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
Expand Down
53 changes: 51 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@


Collective\Html\HtmlServiceProvider::class,

Maknz\Slack\SlackServiceProvider::class, /* slack */
],

/*
Expand Down Expand Up @@ -215,6 +217,8 @@
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,

'Slack' => Maknz\Slack\Facades\Slack::class,
],

// デモ稼働時の特有機能
Expand Down
122 changes: 122 additions & 0 deletions config/slack.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php

return [

/*
|-------------------------------------------------------------
| Incoming webhook endpoint
|-------------------------------------------------------------
|
| The endpoint which Slack generates when creating a
| new incoming webhook. It will look something like
| https://hooks.slack.com/services/XXXXXXXX/XXXXXXXX/XXXXXXXXXXXXXX
|
*/

'endpoint' => env('SLACK_ENDPOINT', false),

/*
|-------------------------------------------------------------
| Default channel
|-------------------------------------------------------------
|
| The default channel we should post to. The channel can either be a
| channel like #general, a private #group, or a @username. Set to
| null to use the default set on the Slack webhook
|
*/

'channel' => env('SLACK_CHANNEL', '#general'),

/*
|-------------------------------------------------------------
| Default username
|-------------------------------------------------------------
|
| The default username we should post as. Set to null to use
| the default set on the Slack webhook
|
*/

'username' => env('SLACK_USERNAME', 'bot'),

/*
|-------------------------------------------------------------
| Default icon
|-------------------------------------------------------------
|
| The default icon to use. This can either be a URL to an image or Slack
| emoji like :ghost: or :heart_eyes:. Set to null to use the default
| set on the Slack webhook
|
*/

'icon' => env('SLACK_ICON', ':eye:'),

/*
|-------------------------------------------------------------
| Link names
|-------------------------------------------------------------
|
| Whether names like @regan should be converted into links
| by Slack
|
*/

'link_names' => false,

/*
|-------------------------------------------------------------
| Unfurl links
|-------------------------------------------------------------
|
| Whether Slack should unfurl links to text-based content
|
*/

'unfurl_links' => false,

/*
|-------------------------------------------------------------
| Unfurl media
|-------------------------------------------------------------
|
| Whether Slack should unfurl links to media content such
| as images and YouTube videos
|
*/

'unfurl_media' => true,

/*
|-------------------------------------------------------------
| Markdown in message text
|-------------------------------------------------------------
|
| Whether message text should be interpreted in Slack's Markdown-like
| language. For formatting options, see Slack's help article: http://goo.gl/r4fsdO
|
*/

'allow_markdown' => true,

/*
|-------------------------------------------------------------
| Markdown in attachments
|-------------------------------------------------------------
|
| Which attachment fields should be interpreted in Slack's Markdown-like
| language. By default, Slack assumes that no fields in an attachment
| should be formatted as Markdown.
|
*/

'markdown_in_attachments' => [],

// Allow Markdown in just the text and title fields
// 'markdown_in_attachments' => ['text', 'title']

// Allow Markdown in all fields
// 'markdown_in_attachments' => ['pretext', 'text', 'title', 'fields', 'fallback']

];