Browse Source

feat(bots): Respect the feature flags

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/10289/head
Joas Schilling 2 years ago
parent
commit
a632fd395b
No known key found for this signature in database GPG Key ID: 74434EFE0D2E2205
  1. 6
      lib/Controller/BotController.php
  2. 8
      lib/Service/BotService.php

6
lib/Controller/BotController.php

@ -100,6 +100,12 @@ class BotController extends AEnvironmentAwareController {
$botAttempt->getBotServer()->getSecret(),
$message
);
if (!($botAttempt->getBotServer()->getFeatures() & Bot::FEATURE_RESPONSE)) {
$this->logger->debug('Not accepting response from bot ID ' . $botAttempt->getBotServer()->getId() . ' because the feature is disabled for it');
throw new \InvalidArgumentException('Feature not enabled for bot', Http::STATUS_BAD_REQUEST);
}
return $botAttempt;
} catch (UnauthorizedException) {
}

8
lib/Service/BotService.php

@ -269,9 +269,15 @@ class BotService {
$this->logger->warning('Can not find bot by ID ' . $botConversation->getBotId() . ' for token ' . $botConversation->getToken());
continue;
}
$botServer = $serversMap[$botConversation->getBotId()];
if (!($botServer->getFeatures() & Bot::FEATURE_WEBHOOK)) {
$this->logger->debug('Not sending webhook to bot ID ' . $botConversation->getBotId() . ' because the feature is disabled for it');
continue;
}
$bot = new Bot(
$serversMap[$botConversation->getBotId()],
$botServer,
$botConversation,
);

Loading…
Cancel
Save