diff --git a/.gitignore b/.gitignore index 6ce6155..58f5887 100755 --- a/.gitignore +++ b/.gitignore @@ -22,7 +22,7 @@ Thumbs.db # composer itself is not needed composer.phar - +composer.lock # Mac DS_Store Files .DS_Store diff --git a/composer.json b/composer.json index 5400117..b277210 100755 --- a/composer.json +++ b/composer.json @@ -31,7 +31,8 @@ "kartik-v/yii2-grid": "dev-master", "kartik-v/yii2-widget-datetimepicker": "dev-master", "edofre/yii2-fullcalendar-scheduler": "V1.1.12", - "asmoday74/yii2-ckeditor5": "*" + "asmoday74/yii2-ckeditor5": "*", + "kavalar/telegram_bot": "^0.1.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 3e9fac4..5d1ff3f 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\TelegramBotService; use yii\filters\auth\CompositeAuth; use yii\filters\auth\HttpBearerAuth; use yii\filters\auth\QueryParamAuth; @@ -59,11 +60,26 @@ class ProfileController extends \yii\rest\Controller public function actionAddToInterview() { if (\Yii::$app->request->isPost) { + $attributes = \Yii::$app->request->post(); + $model = new InterviewRequest(); - $model->attributes = \Yii::$app->request->post(); + $model->attributes = $attributes; $model->created_at = time(); $model->user_id = \Yii::$app->user->id; - if ($model->save()){ + + if ($model->save()) { + $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']}"; + + $bot = new TelegramBotService($token); + $bot->sendMessageTo($chat_id, $message); return ['status' => 'success']; }