Commit 12239f46 authored by Chris Hamper's avatar Chris Hamper Committed by Chris Hamper
Browse files

Issue #2796549 by hampercm, TorreyToomajanian: Alexa webhook fails due to multiple issues

parent cf98155f
Loading
Loading
Loading
Loading
+16 −23
Original line number Diff line number Diff line
@@ -12,18 +12,11 @@

namespace Drupal\alexa_webhook\Controller;


use Alexa\Request\Certificate;
use Drupal\alexa_webhook\AlexaEvent;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;

use Alexa\Request\IntentRequest;
use Alexa\Request\LaunchRequest;
use Alexa\Response\Response;

use Drupal\alexa_webhook\AlexaEvent;

class AlexaWebhookController extends ControllerBase {
  /**
@@ -35,7 +28,6 @@ class AlexaWebhookController extends ControllerBase {
      try {
        // Use our own version of the Certificate class so we can implement
        // Drupal caching of a downloaded certificate.
        object_log('request', $request->headers->get('signature'));
        $certificate = new DrupalCertificate($request->headers->get('signaturecertchainurl'), $request->headers->get('signature'));

        $config = \Drupal::config('alexa_webhook.settings');
@@ -46,28 +38,29 @@ class AlexaWebhookController extends ControllerBase {
        // Parse and validate the request.
        $alexaRequest = $alexa->fromData();

      } catch (InvalidArgumentException $e) {
        // @TODO this is not firing up so any invalid requests will just PHP Error for now
        echo $e->getMessage();
      }

        $response = new \Alexa\Response\Response;

        $dispatcher = \Drupal::service('event_dispatcher');
      $e = new AlexaEvent($alexaRequest, $response);
      $event = $dispatcher->dispatch('alexaevent.request', $e);
        $event = new AlexaEvent($alexaRequest, $response);
        $dispatcher->dispatch('alexaevent.request', $event);

        return new JsonResponse($response->render());
      }
      catch (\InvalidArgumentException $e) {
        watchdog_exception('alexa_webhook', $e);
      }
    }

    return new JsonResponse(NULL, 500);
  }

}

/**
 * Overload the default Amazon Alexa App library Certificate class to allow
  * Drupal based caching of the downloaded Amazon certificate.
 * Drupal-based caching of the downloaded Amazon certificate.
 */
class DrupalCertificate extends \Alexa\Request\Certificate {
class DrupalCertificate extends Certificate {
  public function getCertificate() {
    $cid = 'alexa:certificate:' . $this->certificateUrl;
    $certificate = NULL;