This repository has been archived by the owner on Dec 31, 2019. It is now read-only.
forked from anselmdk/activecollab-slack
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunctions.php
69 lines (59 loc) · 1.72 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* @param $email
* @param $token
* @return mixed
*/
function slack_get_user_by_email($email, $token) {
static $users;
if ($token) {
if (!$users) {
// @todo cache users.list
$slack = new Slack($token);
$response = $slack->call('users.list');
if ($response['ok']) {
$users = $response['members'];
}
}
foreach ($users as $user) {
if ($user['profile']['email'] == $email) {
return $user;
}
}
}
}
/**
* @param $message
* @param $channel
* @param $token
*/
function slack_post_message($message, $channel, $token) {
if ($token) {
$slack = new Slack($token);
$slack->call('chat.postMessage', array(
'channel' => $channel,
'text' => $message,
'username' => 'ActiveCollab',
'as_user' => FALSE,
'icon_url' => defined('ASSETS_URL') ? ASSETS_URL . '/images/system/default/application-branding/logo.80x80.png' : '',
'link_names' => 1
));
}
}
/**
* @param string $customField1
* @return string
*/
function slack_get_channel($customField1 = '') {
$default = defined('SLACK_DEFAULT_CHANNEL') ? SLACK_DEFAULT_CHANNEL : '#general';
return !empty($customField1) ? $customField1 : $default;
}
/**
* @param string $customField2
* @return mixed|string
*/
function slack_get_token($customField2 = '') {
$default = defined('SLACK_API_TOKEN') ? SLACK_API_TOKEN : '';
return !empty($customField2) && defined('SLACK_API_TOKEN_' . strtoupper($customField2)) ?
constant('SLACK_API_TOKEN_' . strtoupper($customField2)) : $default;
}