diff --git a/composer.json b/composer.json index b277210..6195868 100755 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "kartik-v/yii2-widget-datetimepicker": "dev-master", "edofre/yii2-fullcalendar-scheduler": "V1.1.12", "asmoday74/yii2-ckeditor5": "*", - "kavalar/telegram_bot": "^0.1.0" + "kavalar/telegram_bot": "^0.2.0" }, "require-dev": { "yiisoft/yii2-debug": "~2.0.0", diff --git a/frontend/modules/api/controllers/ProfileController.php b/frontend/modules/api/controllers/ProfileController.php index 5d1ff3f..749a62b 100644 --- a/frontend/modules/api/controllers/ProfileController.php +++ b/frontend/modules/api/controllers/ProfileController.php @@ -6,6 +6,7 @@ use common\behaviors\GsCors; use common\classes\Debug; use common\models\InterviewRequest; use frontend\modules\api\models\ProfileSearchForm; +use kavalar\BotNotificationTemplateProcessor; use kavalar\TelegramBotService; use yii\filters\auth\CompositeAuth; use yii\filters\auth\HttpBearerAuth; @@ -71,12 +72,17 @@ class ProfileController extends \yii\rest\Controller $token = \Yii::$app->params['telegramBotToken']; $chat_id = \Yii::$app->params['telegramBotChatId']; - $message = - "Пришёл запрос на интервью.\n". - "Профиль: {$attributes['profile_id']}\n". - "Телефон: {$attributes['phone']}\n". - "Email: {$attributes['email']}\n". - "Комментарий: {$attributes['comment']}"; + $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);