summaryrefslogtreecommitdiff
path: root/www/index.php
blob: c7459a4147925ec6f6c1e96a8e3ab017dc59b303 (plain) (blame)
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
<?php

use \NeonXP\TelegramApi\Telegram;
use \Doctrine\Common\Annotations\AnnotationRegistry;

require __DIR__ . '/../vendor/autoload.php';

AnnotationRegistry::registerAutoloadNamespace(
    'JMS\Serializer\Annotation',
    __DIR__.'/../vendor/jms/serializer/src'
);

$telegram = new Telegram([
    'token' => getenv('TELEGRAM_BOT_TOKEN'),
]);

if (getenv('env') == 'dev') {
    $cache = new \Doctrine\Common\Cache\ArrayCache();
    $dozorApi = new \NeonXP\DozorApi($cache);
    $telegram->setCache($cache);
    $telegram->setScript(\NeonXP\BotScript::getScript($telegram, $dozorApi));
    while(1) {
        $telegram->handleGetUpdates();
        sleep(1);
    }
} else {
    $cache = new \Doctrine\Common\Cache\ApcuCache();
    $dozorApi = new \NeonXP\DozorApi($cache);
    $telegram->setCache($cache);
    $telegram->setScript(\NeonXP\BotScript::getScript($telegram, $dozorApi));
    $telegram->handleWebhook();
}