/** * Test run triggers the run on the command */ public function testRun() { $apiClient = new ApiClient("test"); $args = "arg1 arg2"; $update = new Update(["message" => ["text" => "/test " . $args]]); $command = $this->getMockCommand(["run"]); $command->setTrigger("test"); $command->expects($this->once())->method("run")->with($args, $update->message, $apiClient); $handler = new CommandHandler($apiClient); $handler->register($command); $handler->run($update); }
*/ $app = new Slim(); $app->telegram = function () { return new ApiClient(TELEGRAM_BOT_AUTH_TOKEN); }; /** * Here's the endpoint where Telegram will send it's updates to. Register your * commands in the CommandHandler in here. */ $app->post("/webhook", function () use($app) { /** @var Update $update */ $update = $app->telegram->entityFromBody($app->request->getBody(), new Update()); if ($update->message instanceof Message) { try { // Register your commands here $handler = new CommandHandler($app->telegram); $handler->register(new HelloWorldCommand("hello")); $handler->run($update); } catch (\Exception $e) { echo $e->getMessage(); $app->response()->setStatus(500); } } else { echo "Couldn't find the Message in the body."; $app->response()->setStatus(400); } })->name("webhook"); /** * Install webhook with Telegram API. Uses the current url and "webhook" route. * POST to this URL to install your webhook with Telegram. *