Fix slack errors when variables are not set (#13476)

This commit is contained in:
Tony Murray
2021-11-05 22:30:30 -05:00
committed by GitHub
parent e7a26e8faf
commit 1ff48018fa

View File

@@ -40,22 +40,22 @@ class Slack extends Transport
{
$host = $api['url'];
$curl = curl_init();
$slack_msg = html_entity_decode(strip_tags($obj['msg']), ENT_QUOTES);
$slack_msg = html_entity_decode(strip_tags($obj['msg'] ?? ''), ENT_QUOTES);
$color = self::getColorForState($obj['state']);
$data = [
'attachments' => [
0 => [
'fallback' => $slack_msg,
'color' => $color,
'title' => $obj['title'],
'title' => $obj['title'] ?? null,
'text' => $slack_msg,
'mrkdwn_in' => ['text', 'fallback'],
'author_name' => $api['author_name'],
'author_name' => $api['author_name'] ?? null,
],
],
'channel' => $api['channel'],
'username' => $api['username'],
'icon_emoji' => ':' . $api['icon_emoji'] . ':',
'channel' => $api['channel'] ?? null,
'username' => $api['username'] ?? null,
'icon_emoji' => isset($api['icon_emoji']) ? ':' . $api['icon_emoji'] . ':' : null,
];
$alert_message = json_encode($data);
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);