public function Webhook::sendWebHook in Fastly 8.3
Sends request to WebHookURL.
Parameters
string $message: Webhook message, pass through t() or SafeMarkup::format first.
string $type: Webhook type.
Return value
mixed FALSE if webhook notification are disabled or an unsupported type.
File
- src/
Services/ Webhook.php, line 74
Class
- Webhook
- Class Webhook.
Namespace
Drupal\fastly\ServicesCode
public function sendWebHook($message, $type) {
if (!$this->config
->get('webhook_enabled') || !in_array($type, $this->config
->get('webhook_notifications'))) {
return FALSE;
}
$text = $message;
$headers = [
'Content-type: application/json',
];
$body = [
"text" => $text,
"username" => "fastly-drupal-bot",
"icon_emoji" => ":airplane:",
];
$option = [
"headers" => $headers,
"connect_timeout" => $this->webhookConnectTimeout,
"json" => $body,
];
// @TODO: handle exceptions.
$this->httpClient
->request("POST", $this->config
->get('webhook_url'), $option);
}