-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathModule.php
71 lines (59 loc) · 1.93 KB
/
Module.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* @copyright Copyright © Alexandr Kozhevnikov (onmotion)
* @package yii2-telegram
* Date: 02.08.2016
*/
namespace onmotion\telegram;
use yii\base\UserException;
use yii\helpers\Url;
/**
* telegram module definition class
*/
class Module extends \yii\base\Module implements \yii\base\BootstrapInterface
{
public $API_KEY = null;
public $BOT_NAME = null;
public $hook_url = null;
public $PASSPHRASE = null;
public $userCommandsPath = null;
public $timeBeforeResetChatHandler = 0;
public $db = 'db';
public $options = [];
/**
* @inheritdoc
*/
public $controllerNamespace = 'onmotion\telegram\controllers';
/**
* @inheritdoc
*/
public function init()
{
if (empty($this->API_KEY) || empty($this->BOT_NAME) || empty($this->hook_url))
throw new UserException('You must set API_KEY, BOT_NAME, hook_url');
if (empty($this->PASSPHRASE))
throw new UserException('You must set PASSPHRASE');
parent::init();
// set up i8n
if (empty(\Yii::$app->i18n->translations['tlgrm'])) {
\Yii::$app->i18n->translations['tlgrm'] = [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => __DIR__ . '/messages',
//'forceTranslation' => true,
];
}
$this->options = [
'initChat' => Url::to(['/telegram/default/init-chat']),
'destroyChat' => Url::to(['/telegram/default/destroy-chat']),
'getAllMessages' => Url::to(['/telegram/chat/get-all-messages']),
'getLastMessages' => Url::to(['/telegram/chat/get-last-messages']),
'initialMessage' => \Yii::t('tlgrm', 'Write your question...'),
];
}
public function bootstrap($app)
{
if ($app instanceof \yii\console\Application) {
$this->controllerNamespace = 'onmotion\telegram\commands';
}
}
}