You are here

zoomapi.webhooks.inc in Zoom API 7.2

Page callbacks for Zoom API module.

File

zoomapi.webhooks.inc
View source
<?php

/**
 * @file
 * Page callbacks for Zoom API module.
 */

/**
 * Page callback: Zoom API Webhooks.
 */
function zoomapi_webhooks_callback() {
  $payload = trim(@file_get_contents('php://input'));
  $data = drupal_json_decode($payload, TRUE);
  try {
    $webhook_part = _zoomapi_get_webhook_url_part(request_uri()) ?: 'default';
    if (!variable_get('zoomapi_webhooks_log_disabled', FALSE)) {
      try {
        $record = [
          'url' => $_SERVER['HTTP_HOST'] . request_uri(),
          'url_part' => $webhook_part,
          'ip_address' => ip_address(),
          'event' => !empty($data['event']) ? $data['event'] : '',
          'data' => serialize($data),
          'realm' => zoomapi_realm(),
          'created' => REQUEST_TIME,
        ];
        db_insert('zoomapi_webhooks_log')
          ->fields($record)
          ->execute();
      } catch (\Exception $e) {

        // Avoid stopping the webhook event from being handled because there
        // was an issue writing it to the logs.
        watchdog(__FUNCTION__, 'Unable to write Zoom api webhooks log. Error: @e', [
          '@e' => $e
            ->getMessage(),
        ], WATCHDOG_ERROR);
      }
    }

    // @todo validate meeting uuid (with host_id?) in meeting tracker table before
    // invoking hook?
    module_invoke_all('zoomapi_webhooks', $data);
    drupal_add_http_header('status', 201);
    drupal_json_output([
      'status' => 'ok',
    ]);
    drupal_exit();
  } catch (\Exception $e) {
    watchdog(__FUNCTION__, 'Unable to handle ZoomAPI webhook. Error: @e', [
      '@e' => $e
        ->getMessage(),
    ], WATCHDOG_ERROR);
    drupal_add_http_header('status', 400);
    drupal_exit();
  }
}

Functions

Namesort descending Description
zoomapi_webhooks_callback Page callback: Zoom API Webhooks.