diff --git a/.gitignore b/.gitignore index 58f5887..b096df8 100755 --- a/.gitignore +++ b/.gitignore @@ -22,7 +22,7 @@ Thumbs.db # composer itself is not needed composer.phar -composer.lock +/composer.lock # Mac DS_Store Files .DS_Store diff --git a/composer.json b/composer.json index 6195868..41ce07d 100755 --- a/composer.json +++ b/composer.json @@ -32,7 +32,8 @@ "kartik-v/yii2-widget-datetimepicker": "dev-master", "edofre/yii2-fullcalendar-scheduler": "V1.1.12", "asmoday74/yii2-ckeditor5": "*", - "kavalar/telegram_bot": "^0.2.0" + "kavalar/telegram_bot": "^0.2.0", + "kavalar/yii2-telegram-bot": "^0.1.0" }, "require-dev": { "yiisoft/yii2-debug": "~2.0.0", diff --git a/frontend/config/main.php b/frontend/config/main.php index 7899e29..ef65dd8 100755 --- a/frontend/config/main.php +++ b/frontend/config/main.php @@ -77,6 +77,17 @@ return [ ['class' => 'yii\rest\UrlRule', 'controller' => 'skills'], ], ], + 'telegram_bot' => [ + 'class' => 'kavalar\TelegramBotApi', + 'templates' => [ + 'interview_request' => + "Пришёл запрос на интервью.\n". + "Профиль: ~profile_id~\n". + "Телефон: ~phone~\n". + "Email: ~email~\n". + "Комментарий: ~comment~" + ], + ], ], 'params' => $params, diff --git a/frontend/modules/api/controllers/ProfileController.php b/frontend/modules/api/controllers/ProfileController.php index 749a62b..2c7469f 100644 --- a/frontend/modules/api/controllers/ProfileController.php +++ b/frontend/modules/api/controllers/ProfileController.php @@ -69,23 +69,7 @@ class ProfileController extends \yii\rest\Controller $model->user_id = \Yii::$app->user->id; if ($model->save()) { - $token = \Yii::$app->params['telegramBotToken']; - $chat_id = \Yii::$app->params['telegramBotChatId']; - - $templates = [ - 'interview_request' => - "Пришёл запрос на интервью.\n". - "Профиль: ~profile_id~\n". - "Телефон: ~phone~\n". - "Email: ~email~\n". - "Комментарий: ~comment~" - ]; - - $templateProcessor = new BotNotificationTemplateProcessor($templates); - $message = $templateProcessor->renderTemplate('interview_request', $attributes); - - $bot = new TelegramBotService($token); - $bot->sendMessageTo($chat_id, $message); + \Yii::$app->telegram_bot->sendRenderedMessage('interview_request', $attributes); return ['status' => 'success']; }