Skip to content
This repository was archived by the owner on Mar 13, 2023. It is now read-only.

Commit 6cf0f7c

Browse files
committed
add slack
1 parent cb394b8 commit 6cf0f7c

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
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 App\Repositories\PostRepository;
6+
use GuzzleHttp\Exception\GuzzleException;
7+
use Illuminate\Http\Request;
8+
9+
class SlackInvitationController extends Controller
10+
{
11+
12+
/**
13+
* Show the application dashboard.
14+
*
15+
* @return \Illuminate\Http\Response
16+
*/
17+
public function invite()
18+
{
19+
$result = $this->request_invitation('[email protected]');
20+
21+
22+
}
23+
24+
function request_invitation($email)
25+
{
26+
// users.admin.invite is undocumented API, keep in mind.
27+
$api_response = $this->call_api('/api/users.admin.invite?t=' . time(), [
28+
'email' => $email,
29+
'set_active' => 'true',
30+
'_attempts' => '1',
31+
]);
32+
dd($api_response);
33+
if ($api_response->ok !== true) {
34+
throw new \RuntimeException('Slack API response not ok, error:' . $api_response->error); // TODO more nice Exception
35+
}
36+
}
37+
function call_api($path, $params = [])
38+
{
39+
$client = new \GuzzleHttp\Client([
40+
'base_uri' => "https://slack.com/"
41+
]);
42+
var_dump(env('SLACK_API'));
43+
var_dump(env('SLACK_TOKEN'));
44+
45+
try {
46+
$api_response_raw = $client->request('post', $path, [
47+
'form_params' => array_merge(['token' => env('SLACK_API')], $params)
48+
]);
49+
} catch (GuzzleException $e) {
50+
}
51+
$api_response = json_decode($api_response_raw->getBody());
52+
if ($api_response === null) {
53+
throw new \RuntimeException('Slack API response an invalid json'); // TODO more nice Exception
54+
}
55+
return $api_response;
56+
}
57+
}

routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
{
1616
/** Authenticate Route */
1717
Auth::routes();
18+
Route::get('/slack/invite','SlackInvitationController@invite');
1819
Route::get('/auth/{provider}', 'Auth\LoginController@redirectToProvider');
1920
Route::get('/callback/{provider}', 'Auth\LoginController@handleProviderCallback');
2021
/** Profile Route */

0 commit comments

Comments
 (0)