Skip to content

Commit 55f4d00

Browse files
feat(hackathon): Add Slack API functionality 💪
1 parent 8f0401c commit 55f4d00

File tree

9 files changed

+212
-7
lines changed

9 files changed

+212
-7
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
7+
use SlackUser;
8+
use SlackChat;
9+
use App\Http\Requests;
10+
use App\Http\Controllers\Controller;
11+
12+
class SlackController extends Controller
13+
{
14+
/**
15+
* Return all data to the Slack API dashboard
16+
* @return mixed
17+
*/
18+
public function getPage()
19+
{
20+
$members = $this->getAllUsersOnYourTeam(4);
21+
22+
return view('api.slack')->withMembers($members);
23+
}
24+
25+
/**
26+
* Get All Users on Your Team
27+
* @return array
28+
*/
29+
private function getAllUsersOnYourTeam($count = null)
30+
{
31+
$list = (array)SlackUser::lists();
32+
33+
if (is_null($count)) {
34+
return $list['members'];
35+
}
36+
37+
return array_slice($list['members'], 0, $count);
38+
}
39+
40+
/**
41+
* Send Message to Channel or Group
42+
* @param Request $request
43+
* @return Session
44+
*/
45+
public function sendMessageToTeam(Request $request)
46+
{
47+
$this->validate($request, [
48+
'message' => 'required'
49+
]);
50+
51+
$message = $request->input('message') . ' #FromLaravelHackathonStarter :smile:';
52+
53+
SlackChat::message('#general', $message);
54+
55+
return redirect()->back()->with('info','Your Message has been sent successfully');
56+
}
57+
}

app/Http/routes.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@
121121
'middleware' => ['auth']
122122
]);
123123

124+
Route::get('/api/slack', [
125+
'uses' => 'SlackController@getPage',
126+
'as' => 'api.slack',
127+
'middleware' => ['auth']
128+
]);
129+
130+
Route::post('/slack/message', [
131+
'uses' => 'SlackController@sendMessageToTeam',
132+
'as' => 'slack.message',
133+
'middleware' => ['auth']
134+
]);
135+
124136
Route::post('/tweet/new', [
125137
'uses' => 'TwitterController@sendTweet',
126138
'as' => 'tweet.new',

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"aloha/twilio": "^2.0",
1818
"fabpot/goutte": "^3.1",
1919
"mjerwin/clockwork-sms": "^0.9.1",
20-
"lob/lob-php": "^1.6"
20+
"lob/lob-php": "^1.6",
21+
"vluzrmos/slack-api": "^0.4.6"
2122
},
2223
"require-dev": {
2324
"fzaninotto/faker": "~1.4",

composer.lock

Lines changed: 49 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/app.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
GrahamCampbell\GitHub\GitHubServiceProvider::class,
154154
Thujohn\Twitter\TwitterServiceProvider::class,
155155
Aloha\Twilio\Support\Laravel\ServiceProvider::class,
156+
Vluzrmos\SlackApi\SlackApiServiceProvider::class,
156157

157158
/*
158159
* Application Service Providers...
@@ -212,6 +213,18 @@
212213
'GitHub' => GrahamCampbell\GitHub\Facades\GitHub::class,
213214
'Twitter' => Thujohn\Twitter\Facades\Twitter::class,
214215
'Twilio' => Aloha\Twilio\Support\Laravel\Facade::class,
216+
'SlackApi' => Vluzrmos\SlackApi\Facades\SlackApi::class,
217+
'SlackChannel' => Vluzrmos\SlackApi\Facades\SlackChannel::class,
218+
'SlackChat' => Vluzrmos\SlackApi\Facades\SlackChat::class,
219+
'SlackGroup' => Vluzrmos\SlackApi\Facades\SlackGroup::class,
220+
'SlackFile' => Vluzrmos\SlackApi\Facades\SlackFile::class,
221+
'SlackSearch' => Vluzrmos\SlackApi\Facades\SlackSearch::class,
222+
'SlackInstantMessage' => Vluzrmos\SlackApi\Facades\SlackInstantMessage::class,
223+
'SlackUser' => Vluzrmos\SlackApi\Facades\SlackUser::class,
224+
'SlackStar' => Vluzrmos\SlackApi\Facades\SlackStar::class,
225+
'SlackUserAdmin' => Vluzrmos\SlackApi\Facades\SlackUserAdmin::class,
226+
'SlackRealTimeMessage' => Vluzrmos\SlackApi\Facades\SlackRealTimeMessage::class,
227+
'SlackTeam' => Vluzrmos\SlackApi\Facades\SlackTeam::class,
215228

216229
],
217230

config/services.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,9 @@
7171
'redirect' => env('LINKEDIN_CALLBACK_URL')
7272
],
7373

74+
'slack' => [
75+
'token' => env('SLACK_TOKEN')
76+
]
77+
7478

7579
];

resources/views/api/slack.blade.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
@extends('layouts.master')
2+
3+
@section('content')
4+
<div class="main-container">
5+
@include('layouts.partials.alerts')
6+
7+
<div class="page-header">
8+
<h2><i style="color: #f00" class="fa fa-slack"></i> Slack API</h2>
9+
</div>
10+
11+
<div class="btn-group btn-group-justified">
12+
<a href="https://github.com/vluzrmos/laravel-slack-api" target="_blank" class="btn btn-primary">
13+
<i class="fa fa-check-square-o"></i> Laravel Slack
14+
</a>
15+
<a href="https://api.slack.com/" target="_blank" class="btn btn-primary">
16+
<i class="fa fa-code-fork"></i> REST API
17+
</a>
18+
</div>
19+
20+
<br>
21+
22+
<h3> Get All Users On Your Team (RED-CREEK)</h3>
23+
24+
@if ($members)
25+
<table class="table table-striped table-bordered">
26+
<thead>
27+
<tr>
28+
<th>No</th>
29+
<th>Picture</th>
30+
<th>Full Name</th>
31+
<th>Slack Handle</th>
32+
</tr>
33+
</thead>
34+
<tbody>
35+
36+
<?php $kar = 1; ?>
37+
@foreach ($members as $member)
38+
<tr>
39+
<td>{{ $kar }}</td>
40+
<td><img src="{{ $member->profile->image_48 }}" /></td>
41+
<td>{{ $member->profile->real_name }}</td>
42+
<td>{{ $member->name }}</td>
43+
</tr>
44+
<?php $kar++ ?>
45+
@endforeach
46+
</tbody>
47+
</table>
48+
@endif
49+
50+
<h3> Send Message to a Slack Channel Or Group</h3>
51+
52+
<div class="row">
53+
<div class="col-sm-6">
54+
<form role="form" method="POST" action="{{ route('slack.message') }}">
55+
{!! csrf_field() !!}
56+
<div class="form-group{{ $errors->has('message') ? ' has-error' : '' }}">
57+
<label class="control-label">Message</label>
58+
<input type="text" name="message" class="form-control">
59+
@if ($errors->has('message'))
60+
<span class="help-block">{{ $errors->first('message') }}</span>
61+
@endif
62+
</div>
63+
<button type="submit" class="btn btn-default">
64+
<i class="fa fa-location-arrow"></i> Send
65+
</button>
66+
</form>
67+
</div>
68+
</div>
69+
70+
</div>
71+
@stop

resources/views/apidashboard.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,17 @@
169169
</div>
170170
</a>
171171
</div>
172-
<div class="col-sm-4">
172+
{{-- <div class="col-sm-4">
173173
<a href="/api/bitgo" style="color: #fff">
174174
<div style="background-color: #142834" class="panel panel-default">
175175
<div class="panel-body">
176176
<img src="http://i.imgur.com/v753soI.png" height="40"> BitGo
177177
</div>
178178
</div>
179179
</a>
180-
</div>
180+
</div> --}}
181181
<div class="col-sm-4">
182-
<a href="/api/bitgo" style="color: #fff">
182+
<a href="/api/slack" style="color: #fff">
183183
<div style="background-color: #4d394b" class="panel panel-default">
184184
<div class="panel-body">
185185
<img src="http://i.imgur.com/fbNYOzm.png" height="40"> Slack

resources/views/layouts/master.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<div class="container">
1717
@yield('content')
1818
</div>
19-
<footer class="footer navbar-fixed-bottom">
19+
<footer class="footer">
2020
<div class="container text-center">
2121
<p class="pull-left">© 2015 Company, Inc. All Rights Reserved</p>
2222
<ul class="pull-right list-inline">

0 commit comments

Comments
 (0)