/** * @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)); } }
public function register($code, $provider, $providerId, $email = '') { $data = ['email' => $email, 'token' => $code, 'api_key' => str_random(50), 'plan' => 0, 'provider_id' => $providerId, 'provider' => $provider]; $user = User::create($data); \Slack::send('A new user has registered.'); return $user; }
public function output($message, $sendToSlack = true) { $message = '`[' . strtoupper(app('env')) . ']` ' . $message; $this->info(str_replace('`', '', $message)); if ($sendToSlack) { \Slack::send($message); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $s3 = AWS::get('s3'); $s3Bucket = 'buildbrighton-bbms'; if (Request::hasFile('image')) { $file = Request::file('image'); $event = Request::get('textevent'); $time = Request::get('time'); $fileData = Image::make($file)->encode('jpg', 80); $date = Carbon::createFromFormat('YmdHis', $event); $folderName = $date->hour . ':' . $date->minute . ':' . $date->second; try { $newFilename = \App::environment() . '/cctv/' . $date->year . '/' . $date->month . '/' . $date->day . '/' . $folderName . '/' . $time . '.jpg'; $s3->putObject(array('Bucket' => $s3Bucket, 'Key' => $newFilename, 'Body' => $fileData, 'ACL' => 'public-read', 'ContentType' => 'image/jpg', 'ServerSideEncryption' => 'AES256')); } catch (\Exception $e) { \Log::exception($e); } //Log::debug('Image saved :https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/'.$newFilename); } if (Request::get('eventend') == 'true') { $event = Request::get('textevent'); $date = Carbon::createFromFormat('YmdHis', $event); $folderName = $date->hour . ':' . $date->minute . ':' . $date->second; $iterator = $s3->getIterator('ListObjects', array('Bucket' => $s3Bucket, 'Prefix' => \App::environment() . '/cctv/' . $date->year . '/' . $date->month . '/' . $date->day . '/' . $folderName)); $images = []; $imageDurations = []; foreach ($iterator as $object) { $images[] = 'https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/' . $object['Key']; $imageDurations[] = 35; } if (count($images) <= 2) { //only two images, probably two bad frames //delete them foreach ($iterator as $object) { Log::debug("Deleting small event image " . $object['Key']); $s3->deleteObject(['Bucket' => $s3Bucket, 'Key' => $object['Key']]); } return; } $gc = new GifCreator(); $gc->create($images, $imageDurations, 0); $gifBinary = $gc->getGif(); //Delete the individual frames now we have the gif foreach ($iterator as $object) { //Log::debug("Processed gif, deleting frame, ".$object['Key']); $s3->deleteObject(['Bucket' => $s3Bucket, 'Key' => $object['Key']]); } //Save the gif $newFilename = \App::environment() . '/cctv/' . $date->year . '/' . $date->month . '/' . $date->day . '/' . $folderName . '.gif'; $s3->putObject(array('Bucket' => $s3Bucket, 'Key' => $newFilename, 'Body' => $gifBinary, 'ACL' => 'public-read', 'ContentType' => 'image/gif', 'ServerSideEncryption' => 'AES256')); //Log::debug('Event Gif generated :https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/'.$newFilename); \Slack::to("#cctv")->attach(['image_url' => 'https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/' . $newFilename, 'color' => 'warning'])->send('Movement detected'); } }
/** * Handle the event. * * @param NewMemberNotification $event * @return void */ public function handle(NewMemberNotification $event) { if (\App::environment('production')) { //If the user doesn't have a slack username registered there is nothing we can do if (empty($event->notification->user()->slack_username)) { return; } \Slack::to($event->notification->user()->slack_username)->send($event->notification->message); $event->notification->update(['notified_method' => 'slack', 'notified_at' => Carbon::now()]); } }
public function analyze() { $processors = [new SqlCount($this->queries), new UsingFilesort($this->explainResults), new UsingTemporary($this->explainResults), new AllScan($this->explainResults), new NPlusOneProblem($this->queries), new LowCardinality($this->showIndexResults)]; $results = []; foreach ($processors as $processor) { $results = array_merge($results, $processor->getResults()); } $messages = []; foreach ($results as $result) { $message = $result->getMessage() . ' : ' . $result->getAdditionalInfo(); $this->logger->info($message); $messages[] = $message; } $pushSlack = \Config::get('sqlalert.push_slack'); if ($pushSlack) { \Slack::send(implode("\n", $messages)); } }
<?php /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ require_once "internals.php"; require_once "lib/RetriggerController.php"; require_once "lib/DB/TaskQueue.php"; require_once "lib/DB/QueuedTask.php"; require_once "lib/Slack.php"; init_database(); if ($unit = GET_int("unit")) { $queue = new TaskQueue($unit); if ($queue->has_active_task()) { Slack::log("requesting new task, while old task is still running!"); $task = $queue->get_active_task(); $task->reportError("Requested new task, while this task was still running."); } if (!$queue->has_queued_tasks()) { if (!RetriggerController::fillQueue($unit)) { die("No tasks to schedule"); } } $task = $queue->get_oldest_available_queued_task(); if (!$task) { echo json_encode(array("task" => "sleep 60", "id" => 0)); die; } $task->setStarted(); echo json_encode(array("task" => $task->task(), "id" => $task->id)); die;
/* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the Closure to execute when that URI is requested. | */ Route::get('/', function () { return View::make('hello'); }); Route::any('/inbound/slack/notshinyunicorn/general', function () { $x = Input::all(); $strText = str_replace("<http://", "", $x["text"]); $strText = str_replace("<https://", "", $strText); if (substr($strText, 0, 23) == "open.spotify.com/track/") { $strText = str_replace("open.spotify.com/track/", "", $strText); $strText = str_replace(">", "", $strText); $strTest = file_get_contents("https://api.spotify.com/v1/tracks/" . $strText); $json = $objJSON = json_decode($strTest); $youtube = new \Madcoda\Youtube(array('key' => $_ENV["YOUTUBE_KEY"])); $videoList = $youtube->searchVideos($json->artists[0]->name . " " . $json->name); if (isset($videoList[0]->id->videoId)) { Slack::to('#' . $x["channel_name"])->send("https://www.youtube.com/watch?v=" . $videoList[0]->id->videoId); } else { Slack::to('#' . $x["channel_name"])->send("No match found for Spotify track."); } } });
/** * Initializes Slack API if credentials are valid. * * @access public * @return bool */ public function initialize_api() { if (!is_null($this->api)) { return true; } /* Load the API library. */ if (!class_exists('Slack')) { require_once 'includes/class-slack.php'; } /* Get the OAuth token. */ $auth_token = $this->get_plugin_setting('auth_token'); /* If the OAuth token, do not run a validation check. */ if (rgblank($auth_token)) { return null; } $this->log_debug(__METHOD__ . "(): Validating API Info."); /* Setup a new Slack object with the API credentials. */ $slack = new Slack($auth_token); /* Run an authentication test. */ $auth_test = $slack->auth_test(); if (rgar($auth_test, 'ok')) { $this->api = $slack; $this->log_debug(__METHOD__ . '(): API credentials are valid.'); return true; } else { $this->log_error(__METHOD__ . '(): API credentials are invalid; ' . $auth_test['error']); return false; } }
<?php $auth_token = '[SLACK AUTH TOKEN HERE]'; $trigger_word = '!coffee'; $responses = array("It's about time {{Aaron}} put the kettle on - off you trot!", "Pop the kettle on {{Jim}} - it's your turn to make a cuppa", "Who wants a drink? {{Aaron}} is heading to the kitchen to make one", "Coffee? Tea? Sugar? Battery acid? Get your orders in as {{Jim}} is making a round", "That's very nice of {{Aaron}} to make a round of tea!", "Mine is milk 2 sugars, please, {{Jim}} - what about everyone else?", "The coffee maker is... {{Aaron}}! Get brewing."); // Include slack library from https://github.com/10w042/slack-api include 'coffee_class.php'; // Remove keyword from the text to extract name to exclude $exclude = str_replace($trigger_word . ' ', '', $_POST['text']); // Connect to Slack // Use authentication token found here: https://api.slack.com/ // Scroll to the bottom and issue a token $Slack = new Slack($auth_token); // Get the info for the channel requested from $data = $Slack->call('channels.info', array('channel' => $_POST['channel_id'])); $coffeeMakers = array(); // Loop through channel members foreach ($data['channel']['members'] as $m) { // Get user data $userData = $Slack->call('users.info', array('user' => $m)); // Check to see if the user is online before adding them to list of brewers $presence = $Slack->call('users.getPresence', array('user' => $m)); $user = $userData['user']; // If there is an exclude, check to see if it matches a user real name (lowercase) // If it does not, add it to the $coffeeMakers array if ($presence['presence'] == 'active') { if ($exclude) { if (!(strpos(strtolower($user['real_name']), strtolower($exclude)) !== false)) { $coffeeMakers[] = $user; } } else {
/** * Send a notification to slack * * @param string $channel * @param string $message */ private function sendSlackNotification($channel, $message) { if (\App::environment('production')) { \Slack::to($channel)->send($message); } }
<?php require 'Slack.php'; $Slack = new Slack(['client_id' => '3760872023.3763031462', 'client_secret' => '52690cf68c50885a85d187bbba4a5d57']); if (isset($_POST['code'])) { try { $token = $Slack->getAccess($_POST['code']); } catch (Exception $e) { //die($e->getMessage()); //renvoyer un chaine vide return false; } if (isset($token)) { print_r($token); } } else { if (isset($_POST['token'])) { $user = $Slack->me($_POST['token']); print_r(json_encode($user)); } else { return 'slack.php'; } }
<?php require_once 'vendor/autoload.php'; $slack = new Slack("xoxp-33881273586-33859906676-33867001956-db01925dcb"); $slack->chatPostMessage("#feedback-message", "@e19940604 say hello to #general");
/** * Handle the event. * * @param MemberActivity $event */ public function handle(MemberActivity $event) { if (\App::environment('production')) { \Slack::send($event->keyFob->user->name . ' is in the space'); } }
<?php require 'vendor/autoload.php'; require 'slack.class.php'; require 'sound.class.php'; use Goutte\Client; $channel = $argv[1]; $outputfile = $argv[2]; if (empty($channel) || empty($outputfile)) { die("Usage: slackcast.php [channel] [outputfile]\r\n"); } if (empty(getenv('SLACK_API')) || empty(getenv('SLACK_USER'))) { die("Please set environment variables SLACK_API and SLACK_USER"); } $sound = new Sound(); $slack = new Slack(array('api_key' => getenv('SLACK_API'), 'slack_user' => getenv('SLACK_USER'))); if ($channel == 'private') { die("Feature coming soon.\r\n"); } $slack->load_channels(); if (empty($slack->channels[$channel])) { die("Channel not found.\r\n"); } $json = $slack->get_channel_history($slack->channels[$channel]['id']); $json->messages = array_reverse($json->messages); foreach ($json->messages as $m) { $message = $m->text; // mute the hubot somewhat if ($slack->users[$m->user]['name'] == 'hubot') { $items = explode(" ", $message); $items = array_slice($items, 0, 10);
/** * Slack message * * @param string $message */ protected function slack($message) { \Slack::to(env('SLACK_CHANNEL'))->send('@theviking @simon @nikolajlovenhardt ' . $message); }