src/Bot.php
public function run($event = null)
    {
        if (null === $event) {
            // check body
            $eventBody = $this->getInputBody();

            if (!Signature::isValid(
                $this->getSignHeaderValue(),
                $eventBody,
                $this->getClient()->getToken()
            )) {
                throw new \RuntimeException('Invalid signature header', 2);
            }
            // check json
            $eventBody = json_decode($eventBody, true);
            if (json_last_error() || empty($eventBody) || !is_array($eventBody)) {
                throw new \RuntimeException('Invalid json request', 3);
            }
            // make event from json
            $event = Factory::makeFromApi($eventBody);
        } elseif (!$event instanceof Event) {
            throw new \RuntimeException('Event must be instance of \Viber\Api\Event', 4);
        }
        // main bot loop
        foreach ($this->managers as $manager) {
            if ($manager->isMatch($event)) {
                $returnValue = $manager->runHandler($event);
                if ($returnValue && $returnValue instanceof Entity) { // reply with entity
                    $this->outputEntity($returnValue);
                }
                break;
            }
        }

        return $this;
    }
public function run($event = null)
    {
        if (null === $event) {
            // check body
            $eventBody = $this->getInputBody();

            if (!Signature::isValid(
                $this->getSignHeaderValue(),
                $eventBody,
                $this->getClient()->getToken()
            )) {
                throw new \RuntimeException('Invalid signature header', 2);
            }
            // check json
            $eventBody = json_decode($eventBody, true);
            if (json_last_error() || empty($eventBody) || !is_array($eventBody)) {
                throw new \RuntimeException('Invalid json request', 3);
            }
            // make event from json
            $event = Factory::makeFromApi($eventBody);
        } elseif (!$event instanceof Event) {
            throw new \RuntimeException('Event must be instance of \Viber\Api\Event', 4);
        }
        // main bot loop
        foreach ($this->managers as $manager) {
            if ($manager->isMatch($event)) {
                $returnValue = $manager->runHandler($event);
                if ($returnValue && $returnValue instanceof Entity) { // reply with entity
                    $this->outputEntity($returnValue);
                }
                break;
            }
        }

        return $this;
    }
public function run ( $ event = null ) { if ( null === $ event ) { // check body $ eventBody = $ this -> getInputBody ( ) ; if ( ! Signature :: isValid ( $ this -> getSignHeaderValue ( ) , $ eventBody , $ this -> getClient ( ) -> getToken ( ) ) ) { throw new \ RuntimeException ( 'Invalid signature header' , 2 ) ; } // check json $ eventBody = json_decode ( $ eventBody , true ) ; if ( json_last_error ( ) || empty ( $ eventBody ) || ! is_array ( $ eventBody ) ) { throw new \ RuntimeException ( 'Invalid json request' , 3 ) ; } // make event from json $ event = Factory :: makeFromApi ( $ eventBody ) ; } elseif ( ! $ event instanceof Event ) { throw new \ RuntimeException ( 'Event must be instance of \Viber\Api\Event' , 4 ) ; } // main bot loop foreach ( $ this -> managers as $ manager ) { if ( $ manager -> isMatch ( $ event ) ) { $ returnValue = $ manager -> runHandler ( $ event ) ; if ( $ returnValue && $ returnValue instanceof Entity ) { // reply with entity $ this -> outputEntity ( $ returnValue ) ; } break ; } } return $ this ; }
Start bot process

@throws \RuntimeException
@param \Viber\Api\Event $event start bot with some event
@return \Viber\Bot
Start bot process