-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
46 lines (34 loc) · 1.16 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
41
42
43
44
45
#!/usr/bin/env php
<?php
use Dotenv\Dotenv;
use SergiX44\Nutgram\Configuration;
use SergiX44\Nutgram\Nutgram;
use TelegramSmartBot\Modules\MainMenu\MainMenuCommand;
use TelegramSmartBot\Tools\Logger\LoggerFactory;
require_once __DIR__ . '/vendor/autoload.php';
$logger = (new LoggerFactory)->getLogger('telegram_bot');
$dotenv = Dotenv::createImmutable(__DIR__, '.env');
$dotenv->load();
try {
$config = new Configuration(
logger: $logger,
);
$bot = new Nutgram($_ENV['TELEGRAM_BOT_TOKEN'], $config);
$commands = [
MainMenuCommand::class,
];
foreach ($commands as $command) {
$class = new $command;
if ($class->haveParams()) {
$bot->onCommand($class->getCommand() . ' {param}', [$class, 'handle']);
$bot->onCallbackQueryData($class->getCommand() . ' {param}', [$class, 'handle']);
} else {
$bot->onCommand($class->getCommand(), [$class, 'handle']);
$bot->onCallbackQueryData($class->getCommand(), [$class, 'handle']);
}
}
$bot->run();
} catch (Exception $e) {
$logger->error($e->getMessage());
$logger->error($e->getTraceAsString());
}