/** * Add the attachments * * @param $attach */ protected function addAttachment($attach) { if (is_array($attach)) { if ($this->is_assoc($attach)) { $attach = [$attach]; } foreach ($attach as $attachElement) { $this->client = $this->client->attach($attachElement); } } }
/** * Send reviews to Slack * * @param array $reviews list of reviews to send * @return boolean successful sending */ public function sendReviews($reviews) { if (!is_array($reviews) || !count($reviews)) { return false; } if (!isset($this->slackSettings['endpoint'])) { if ($this->logger) { $this->logger->error('Reviewer: you should set endpoint in Slack settings'); } return false; } $config = ['username' => 'TJ Reviewer', 'icon' => 'https://i.imgur.com/GX1ASZy.png']; if (isset($this->slackSettings['channel'])) { $config['channel'] = $this->slackSettings['channel']; } $slack = new Slack($this->slackSettings['endpoint'], $config); foreach ($reviews as $review) { $ratingText = ''; for ($i = 1; $i <= 5; $i++) { $ratingText .= $i <= $review['rating'] ? "★" : "☆"; } try { if ($this->firstTime === false) { $slack->attach(['fallback' => "{$ratingText} {$review['title']} — {$review['content']}", 'author_name' => $review['application']['name'], 'author_icon' => $review['application']['image'], 'author_link' => $review['application']['link'], 'color' => $review['rating'] >= 4 ? 'good' : ($review['rating'] == 3 ? 'warning' : 'danger'), 'fields' => [['title' => $review['title'], 'value' => $review['content']], ['title' => 'Rating', 'value' => $ratingText, 'short' => true], ['title' => 'Author', 'value' => "<{$review['author']['uri']}|{$review['author']['name']}>", 'short' => true], ['title' => 'Version', 'value' => $review['application']['version'], 'short' => true], ['title' => 'Country', 'value' => $review['country'], 'short' => true]]])->send(); } $this->storage->set("r{$review['id']}", 1); } catch (Exception $e) { if ($this->logger) { $this->logger->error('Reviewer: exception while sending reviews', ['exception' => $e]); } } } return true; }
/** * Send a message to the configured slack channel * @param $message * @return null */ protected function send($message) { $settings = ['username' => $this->config['slack']['username'], 'channel' => $this->config['slack']['channel']]; $client = new Maknz\Slack\Client($this->config['slack']['endpoint'], $settings); $client->attach(['text' => (string) $message, 'color' => 'good'])->send('New user connected'); }
$hourDirection = strtolower($row[7]); $team[$member] = ['title' => $member, 'value' => '_' . $hours . '_ ' . $hourDirection]; $teamFallback .= $member . ': ' . $hours . ' ' . $hourDirection . String::newLine(); $teamCli[$member] = ['name' => $member, 'hours' => $hours, 'hourDirection' => $hourDirection]; } } } $reader->close(); if (!empty($configuration['slackEndpoint']) && !empty($configuration['channel'])) { Cli::writeOutput('Notifying Slack team', Cli::COLOR_GREEN_DIM); // Instantiate with defaults, so all messages created // will be sent from 'Cyril' and to the #accounting channel // by default. Any names like @regan or #channel will also be linked. $client = new Client($configuration['slackEndpoint'], ['username' => 'HourBank', 'channel' => $configuration['channel'], 'icon' => ':clock4:', 'markdown_in_attachments' => ['fields']]); /** @var $client Message */ !$dryRun && $client->attach(['fallback' => $teamFallback, 'color' => 'bad', 'fields' => $team])->send($headLine); } if ($configuration['markAsDone']) { $modify = new Google_Service_Gmail_ModifyMessageRequest(); $modify->setRemoveLabelIds(['INBOX']); !$dryRun && $service->users_messages->modify($user, $message->getId(), $modify); Cli::writeOutput('Message marked as *done*', Cli::COLOR_YELLOW_DIM); } if ($configuration['removeMessage'] && !$dryRun) { !$dryRun && $service->users_messages->trash($user, $message->getId()); Cli::writeOutput('Message moved to trash!', Cli::COLOR_YELLOW_DIM); } if ($headLine) { Cli::writeOutput(String::newLine() . $headLine . String::newLine(), Cli::COLOR_WHITE_BOLD); } foreach ($teamCli as $member => $data) {