-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.php
40 lines (34 loc) · 1.19 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
use Telegram\Bot\Objects\Update;
use Admin\Api;
use Admin\Events\UpdateWasReceived;
use League\Event\Emitter;
require_once 'vendor/autoload.php';
if(file_exists('.env')) {
$dotenv = Dotenv\Dotenv::createMutable(__DIR__);
$dotenv->load();
}
if(getenv('MOCK_JSON')) {
class mockApi extends Api {
public function getWebhookUpdate($shouldEmitEvent = true): Update {
$content = trim($_ENV['MOCK_JSON'], "'");
$update = new Update(json_decode($content, true));
if ($shouldEmitEvent) {
$this->emitEvent(new UpdateWasReceived($update, $this));
}
return $update;
}
}
$telegram = new mockApi();
} else {
error_log(file_get_contents('php://input'));
$telegram = new Api();
}
$telegram->addCommand(Admin\Commands\NewChatMemberCommand::class);
$telegram->addCommand(Admin\Commands\StartCommand::class);
$telegram->addCommand(Admin\Commands\TextCommand::class);
$telegram->addCommand(Admin\Commands\AddRuleCommand::class);
$emitter = new Emitter();
$emitter->addListener(UpdateWasReceived::class, fn ($e) => $e->handle($e));
$telegram->setEventEmitter($emitter);
$telegram->commandsHandler(true);