You are here

function zoomapi_webhooks_callback in Zoom API 7.2

Same name and namespace in other branches
  1. 7 zoomapi.pages.inc \zoomapi_webhooks_callback()

Page callback: Zoom API Webhooks.

1 string reference to 'zoomapi_webhooks_callback'
zoomapi_menu in ./zoomapi.module
Implements hook_menu().

File

./zoomapi.webhooks.inc, line 11
Page callbacks for Zoom API module.

Code

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();
  }
}