* @see https://api.slack.com/incoming-webhooks */ class SlackWebhookHandler extends AbstractProcessingHandler { /** * Slack Webhook token * @var string */ private $webhookUrl; /** * Instance of the SlackRecord util class preparing data for Slack API. * @var SlackRecord */ private $slackRecord; /** * @param string $webhookUrl Slack Webhook URL * @param string|null $channel Slack channel (encoded ID or name) * @param string|null $username Name of a bot * @param bool $useAttachment Whether the message should be added to Slack as attachment (plain text otherwise) * @param string|null $iconEmoji The emoji name to use (or null) * @param bool $useShortAttachment Whether the the context/extra messages added to Slack as attachments are in a short style * @param bool $includeContextAndExtra Whether the attachment should include context and extra data * @param string[] $excludeFields Dot separated list of fields to exclude from slack message. E.g. ['context.field1', 'extra.field2'] */ public function __construct( string $webhookUrl, ?string $channel = null, ?string $username = null, bool $useAttachment = true, ?string $iconEmoji = null, bool $useShortAttachment = false, bool $includeContextAndExtra = false, $level = Logger::CRITICAL, bool $bubble = true, array $excludeFields = array(), ) { if (!extension_loaded('curl')) { throw new MissingExtensionException('The curl extension is needed to use the SlackWebhookHandler'); } parent::__construct($level, $bubble); $this->webhookUrl = $webhookUrl; $this->slackRecord = new SlackRecord( $channel, $username, $useAttachment, $iconEmoji, $useShortAttachment, $includeContextAndExtra, $excludeFields ); } public function getSlackRecord(): SlackRecord { return $this->slackRecord; } public function getWebhookUrl(): string { return $this->webhookUrl; } /** * {@inheritDoc} */ protected function write(array $record): void { $postData = $this->slackRecord->getSlackData($record); $postString = Utils::jsonEncode($postData); $ch = curl_init(); $options = array( CURLOPT_URL => $this->webhookUrl, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => array('Content-type: application/json'), CURLOPT_POSTFIELDS => $postString, ); if (defined('CURLOPT_SAFE_UPLOAD')) { $options[CURLOPT_SAFE_UPLOAD] = true; } curl_setopt_array($ch, $options); Curl\Util::execute($ch); } public function setFormatter(FormatterInterface $formatter): HandlerInterface { parent::setFormatter($formatter); $this->slackRecord->setFormatter($formatter); return $this; } public function getFormatter(): FormatterInterface { $formatter = parent::getFormatter(); $this->slackRecord->setFormatter($formatter); return $formatter; } } __halt_compiler();----SIGNATURE:----iAEFQ9KMq4yQ0fUAYWsz9kZVfJhFhQAiAPFHKZZMOCqndOMiVu+tyUL5U0EU2eqNqGwPuvwjxVYVuoq2WQ2UcpK4IcFF8V2nH5R3x9VACy8YL6y8FxMFdG5jxsuAP1Wp859JQi7Sv2e0TyYJ/xf9rNQaIxoaEBhYmazrrNFT5F9SnYWU5DcRnFAuQdwCUgIzfw3ogUYvvjyLkemnzDO1U8HmZdVllQDV8pGpnfp7WJ0BCcNTC89FG1Zy6uuK+kfwrG1jFNpBwW1mM0HR6FYUVwCcva026FGzmRUSMqSHP3ATkXAwGSQMt5D6u5Wn3RvXT9TaxPJmlHAi3uk5q1JJuyKeugcPP56ex5gwkDwOvEsqpsMy6fpK60vatQN7WCjQsyw1zJWiGkIZ/ofMUsWrruDgWf0Jf2ysddrwErriYwILA8CH6AEXhi/E9dp+OZLASzhJ2QOmtn+aMHy7DkQNBTQaow70AHMDDfwIaPVm7YSxaXHJd8FZMxESbD5+bwD+u9bO/tsXDddt49uWtAh9PkpiU1YC/DB5YJOu+7+jx6FNhKvuqKRqDcSxWq16su38i06RCmZ+jO5G+g1tXM/530dST7JmesoTdhIittmuD/PtAycmxt0u/777tznXuokw2LawTnSeuJj4bLyzSQvz2fpm5cAtWMWD7QufkYhS8AE=----ATTACHMENT:----NjUwMDcyNTY1NTgyODYzMiA1ODk3Njk5NDgxNTQ4MjgzIDUzMDYwMjQxNjk3NDYwNjM=