-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.php
53 lines (49 loc) · 1.52 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
46
47
48
49
50
51
52
53
<?php
use Telegram\Bot\Objects\Update;
use Base\Api;
require_once 'vendor/autoload.php';
if(file_exists('.env')) {
$dotenv = new Dotenv\Dotenv(__DIR__);
$dotenv->load();
}
if(getenv('MOCK_JSON')) {
class mockApi extends Api{
public function getWebhookUpdate($shouldEmitEvent = true) {
$content = trim(getenv('MOCK_JSON'), "'");
return new Update(json_decode($content, true));
}
}
$telegram = new mockApi();
} else {
error_log(file_get_contents('php://input'));
$telegram = new Api();
}
//$updates = $telegram->getUpdates();
//die();
// Classic commands
$telegram->addCommands([
\Commands\HelpCommand::class,
\Commands\AboutCommand::class,
\Commands\ImportAuthyCommand::class,
\Commands\AddUriCommand::class,
\Commands\GetCommand::class,
\Commands\ListCommand::class,
\Commands\RemainingCommand::class,
\Commands\StartCommand::class,
\Commands\DeleteCommand::class,
\Commands\ShareCommand::class
]);
$update = $telegram->getWebhookUpdate();
if ($update->has('channel_post') ||
($update->has('message') && in_array($update->getMessage()->getFrom()->getId(), explode(',', getenv('BLACKLIST'))))
) {
error_log('################### BLACKLIST ###################');
error_log(file_get_contents('php://input'));
return;
}
foreach(['CallbackQuery', 'Command', 'Document', 'Contact', 'Message'] as $method) {
call_user_func([$telegram, 'process'.$method], $update);
if($telegram->getLastResponse()) {
break;
}
}