You are here

class Webhook in Fastly 7.2

Class Webhook.

Hierarchy

Expanded class hierarchy of Webhook

1 string reference to 'Webhook'
fastly_menu in ./fastly.module
Implements hook_menu().

File

./fastly.webhook.inc, line 6

View source
class Webhook {

  /**
   * Sends request to WebHookURL
   *
   * @param $message
   * @param $type
   *
   * @return mixed
   */
  public function sendMessage($message, $type, $action = null) {
    global $base_url;
    $headers = array(
      'Content-type: application/json',
    );
    $data = json_encode(array(
      "text" => $base_url . " // " . $type . ': ' . $message,
      "username" => "fastly-drupal-bot",
      "icon_emoji" => ":airplane:",
    ));
    $options = array(
      "method" => "POST",
      "data" => $data,
      "connect_timeout" => 15,
      "headers" => $headers,
    );
    $webhookUrl = variable_get('fastly_webhook_url');
    $webhookActions = variable_get('fastly_webhook_events');
    if (in_array($action, $webhookActions)) {
      drupal_http_request($webhookUrl, $options);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Webhook::sendMessage public function Sends request to WebHookURL