/** * @todo Replace basic Exception by the specific * @param Update $update * @throws DialogException */ public function __construct(Update $update) { $username = $update->getMessage()->getFrom()->getUsername(); if (!$username || !in_array($username, $this->allowedUsers)) { throw new DialogException('You have no access to start this dialog'); } parent::__construct($update); }
public function postTelegram() { BufferedSink::createPromise($this->resolver->request)->then(function ($body) { $update = new Update(json_decode($body, true)); $message = $update->getMessage(); if ($message !== null && $message->has('text')) { $this->resolver->telegram->getCommandBus()->handler($message->getText(), $update); } }); }
/** * Check update object for a command and process. * * @param Update $update */ public function processCommand(Update $update) { $message = $update->getMessage(); if ($message !== null && $message->has('text')) { $this->getCommandBus()->handler($message->getText(), $update); } }
/** * Detect Message Type Based on Update Object. * * @param Update $update * * @return string|null */ public function detectMessageType(Update $update) { $types = ['audio', 'document', 'photo', 'sticker', 'video', 'voice', 'contact', 'location', 'text']; return $update->getMessage()->keys()->intersect($types)->pop(); }
/** * Returns Telegram chat object * @return \Telegram\Bot\Objects\Chat */ public function getChat() { return $this->update->getMessage()->getChat(); }
/** * @param Update $update * @return bool */ public function exists(Update $update) { if (!$this->redis->exists($update->getMessage()->getChat()->getId())) { return false; } return true; }