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

Commit 5cd009b

Browse files
committed
Merge pull request #43 from nijibox/feature/post-slack
Slack連携
2 parents cd807c8 + 18425b8 commit 5cd009b

8 files changed

+203
-3
lines changed

.env.example

+6
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,9 @@ OAUTH_ONLY=false
2525
# Google Analytics関連
2626
# scriptの埋め込みをする場合は、下の行をコメントから復旧させた後にIDを記述してください
2727
# GA_TRACKING_ID=
28+
29+
30+
# slackポスト設定
31+
# SLACK_ENDPOINT=https://hooks.slack.com/services/access_token
32+
# SLACK_USERNAME=slack_post_name
33+
# SLACK_ICON=:slack_icon:

.env.mysql.example

+5
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ OAUTH_PROVIDER=null
1919
OAUTH_CLIENT=your-oauth-client-id
2020
OAUTH_SECRET=your-oauth-sercret
2121
OAUTH_REDIRECT=your-oauth-callback-redirect
22+
23+
# slackポスト設定
24+
# SLACK_ENDPOINT=https://hooks.slack.com/services/access_token
25+
# SLACK_USERNAME=slack_post_name
26+
# SLACK_ICON=:slack_icon:

.env.sqlite.exmple

+5
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ OAUTH_PROVIDER=null
1616
OAUTH_CLIENT=your-oauth-client-id
1717
OAUTH_SECRET=your-oauth-sercret
1818
OAUTH_REDIRECT=your-oauth-callback-redirect
19+
20+
# slackポスト設定
21+
# SLACK_ENDPOINT=https://hooks.slack.com/services/access_token
22+
# SLACK_USERNAME=slack_post_name
23+
# SLACK_ICON=:slack_icon:

app/Http/Controllers/ArticleController.php

+8
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
use Validator;
66
use Auth;
77
use DB;
8+
use Config;
89
use App\Http\Requests;
910
use App\Article;
1011
use App\ArticleTag;
1112
use Illuminate\Http\Request;
13+
use Maknz\Slack\Facades\Slack;
1214

1315

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

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"laravel/socialite": "^2.0",
1212
"cebe/markdown": "^1.1",
1313
"laravelcollective/html": "^5.2",
14-
"doctrine/dbal": "^2.5"
14+
"doctrine/dbal": "^2.5",
15+
"maknz/slack": "^1.7"
1516
},
1617
"require-dev": {
1718
"fzaninotto/faker": "~1.4",

composer.lock

+51-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/app.php

+4
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@
166166

167167

168168
Collective\Html\HtmlServiceProvider::class,
169+
170+
Maknz\Slack\SlackServiceProvider::class, /* slack */
169171
],
170172

171173
/*
@@ -215,6 +217,8 @@
215217
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
216218
'Form' => Collective\Html\FormFacade::class,
217219
'Html' => Collective\Html\HtmlFacade::class,
220+
221+
'Slack' => Maknz\Slack\Facades\Slack::class,
218222
],
219223

220224
// デモ稼働時の特有機能

config/slack.php

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|-------------------------------------------------------------
7+
| Incoming webhook endpoint
8+
|-------------------------------------------------------------
9+
|
10+
| The endpoint which Slack generates when creating a
11+
| new incoming webhook. It will look something like
12+
| https://hooks.slack.com/services/XXXXXXXX/XXXXXXXX/XXXXXXXXXXXXXX
13+
|
14+
*/
15+
16+
'endpoint' => env('SLACK_ENDPOINT', false),
17+
18+
/*
19+
|-------------------------------------------------------------
20+
| Default channel
21+
|-------------------------------------------------------------
22+
|
23+
| The default channel we should post to. The channel can either be a
24+
| channel like #general, a private #group, or a @username. Set to
25+
| null to use the default set on the Slack webhook
26+
|
27+
*/
28+
29+
'channel' => env('SLACK_CHANNEL', '#general'),
30+
31+
/*
32+
|-------------------------------------------------------------
33+
| Default username
34+
|-------------------------------------------------------------
35+
|
36+
| The default username we should post as. Set to null to use
37+
| the default set on the Slack webhook
38+
|
39+
*/
40+
41+
'username' => env('SLACK_USERNAME', 'bot'),
42+
43+
/*
44+
|-------------------------------------------------------------
45+
| Default icon
46+
|-------------------------------------------------------------
47+
|
48+
| The default icon to use. This can either be a URL to an image or Slack
49+
| emoji like :ghost: or :heart_eyes:. Set to null to use the default
50+
| set on the Slack webhook
51+
|
52+
*/
53+
54+
'icon' => env('SLACK_ICON', ':eye:'),
55+
56+
/*
57+
|-------------------------------------------------------------
58+
| Link names
59+
|-------------------------------------------------------------
60+
|
61+
| Whether names like @regan should be converted into links
62+
| by Slack
63+
|
64+
*/
65+
66+
'link_names' => false,
67+
68+
/*
69+
|-------------------------------------------------------------
70+
| Unfurl links
71+
|-------------------------------------------------------------
72+
|
73+
| Whether Slack should unfurl links to text-based content
74+
|
75+
*/
76+
77+
'unfurl_links' => false,
78+
79+
/*
80+
|-------------------------------------------------------------
81+
| Unfurl media
82+
|-------------------------------------------------------------
83+
|
84+
| Whether Slack should unfurl links to media content such
85+
| as images and YouTube videos
86+
|
87+
*/
88+
89+
'unfurl_media' => true,
90+
91+
/*
92+
|-------------------------------------------------------------
93+
| Markdown in message text
94+
|-------------------------------------------------------------
95+
|
96+
| Whether message text should be interpreted in Slack's Markdown-like
97+
| language. For formatting options, see Slack's help article: http://goo.gl/r4fsdO
98+
|
99+
*/
100+
101+
'allow_markdown' => true,
102+
103+
/*
104+
|-------------------------------------------------------------
105+
| Markdown in attachments
106+
|-------------------------------------------------------------
107+
|
108+
| Which attachment fields should be interpreted in Slack's Markdown-like
109+
| language. By default, Slack assumes that no fields in an attachment
110+
| should be formatted as Markdown.
111+
|
112+
*/
113+
114+
'markdown_in_attachments' => [],
115+
116+
// Allow Markdown in just the text and title fields
117+
// 'markdown_in_attachments' => ['text', 'title']
118+
119+
// Allow Markdown in all fields
120+
// 'markdown_in_attachments' => ['pretext', 'text', 'title', 'fields', 'fallback']
121+
122+
];

0 commit comments

Comments
 (0)