getMessage($request); $contacts = $handler->getContacts($request); $this->logger->debug(sprintf('SMS REPLY: Processing message "%s"', $message)); $this->logger->debug(sprintf('SMS REPLY: Found IDs %s', implode(',', $contacts->getKeys()))); foreach ($contacts as $contact) { // Set the contact for campaign decisions $this->contactTracker->setSystemContact($contact); $eventResponse = $this->dispatchReplyEvent($contact, $message); if ($eventResponse instanceof Response) { // Last one wins $response = $eventResponse; } } } catch (BadRequestHttpException) { return new Response('invalid request', 400); } catch (NotFoundHttpException) { return new Response('', 404); } catch (NumberNotFoundException $exception) { $this->logger->debug( sprintf( '%s: %s was not found. The message sent was "%s"', $handler->getTransportName(), $exception->getNumber(), !empty($message) ? $message : 'unknown' ) ); } return $response; } private function dispatchReplyEvent(Lead $contact, string $message): ?Response { $replyEvent = new ReplyEvent($contact, trim($message)); $this->eventDispatcher->dispatch($replyEvent, SmsEvents::ON_REPLY); return $replyEvent->getResponse(); } }