|
12 | 12 | use BotMan\BotMan\Messages\Attachments\Image;
|
13 | 13 | use BotMan\BotMan\Messages\Outgoing\Question;
|
14 | 14 | use Symfony\Component\HttpFoundation\Request;
|
| 15 | +use BotMan\BotMan\Drivers\Events\GenericEvent; |
15 | 16 | use Symfony\Component\HttpFoundation\Response;
|
16 | 17 | use Symfony\Component\HttpFoundation\JsonResponse;
|
17 | 18 | use Symfony\Component\HttpFoundation\ParameterBag;
|
@@ -82,6 +83,34 @@ public function matchesRequest()
|
82 | 83 | return ! is_null($this->event->get('user')) || ! is_null($this->event->get('team_domain')) || ! is_null($this->event->get('bot_id'));
|
83 | 84 | }
|
84 | 85 |
|
| 86 | + /** |
| 87 | + * Determine whether a non-message event is matching the current request, and if so, |
| 88 | + * build and return a GenericEvent instance from it. |
| 89 | + * |
| 90 | + * @return GenericEvent|bool|mixed A GenericEvent instance, or the result from |
| 91 | + * the parent class' method (likely false). |
| 92 | + */ |
| 93 | + public function hasMatchingEvent() |
| 94 | + { |
| 95 | + // Retrieve the 'event' part of the payload |
| 96 | + $eventData = $this->payload->get('event'); |
| 97 | + |
| 98 | + // If the event type isn't 'message' (which should go through BotMan::hears), |
| 99 | + // build a GenericEvent and return it |
| 100 | + if (isset($eventData['type']) && $eventData['type'] !== 'message') { |
| 101 | + $eventPayload = json_encode($eventData); |
| 102 | + if ($eventPayload !== false) { |
| 103 | + $event = new GenericEvent($eventPayload); |
| 104 | + $event->setName($eventData['type']); |
| 105 | + |
| 106 | + return $event; |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + // Otherwise, fall back to the parent implementation |
| 111 | + return parent::hasMatchingEvent(); |
| 112 | + } |
| 113 | + |
85 | 114 | /**
|
86 | 115 | * @param \BotMan\BotMan\Messages\Incoming\IncomingMessage $message
|
87 | 116 | * @return \BotMan\BotMan\Messages\Incoming\Answer
|
|
0 commit comments