New interview telegrab bot notification

This commit is contained in:
Ivaniv Anton 2021-08-24 15:14:31 +03:00
parent c8540c41b3
commit 14348e2fae
3 changed files with 1848 additions and 560 deletions

View File

@ -31,7 +31,8 @@
"kartik-v/yii2-grid": "dev-master", "kartik-v/yii2-grid": "dev-master",
"kartik-v/yii2-widget-datetimepicker": "dev-master", "kartik-v/yii2-widget-datetimepicker": "dev-master",
"edofre/yii2-fullcalendar-scheduler": "V1.1.12", "edofre/yii2-fullcalendar-scheduler": "V1.1.12",
"asmoday74/yii2-ckeditor5": "*" "asmoday74/yii2-ckeditor5": "*",
"kavalar/telegram_bot": "^0.1.0"
}, },
"require-dev": { "require-dev": {
"yiisoft/yii2-debug": "~2.0.0", "yiisoft/yii2-debug": "~2.0.0",

2392
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -6,6 +6,7 @@ use common\behaviors\GsCors;
use common\classes\Debug; use common\classes\Debug;
use common\models\InterviewRequest; use common\models\InterviewRequest;
use frontend\modules\api\models\ProfileSearchForm; use frontend\modules\api\models\ProfileSearchForm;
use kavalar\TelegramBotService;
use yii\filters\auth\CompositeAuth; use yii\filters\auth\CompositeAuth;
use yii\filters\auth\HttpBearerAuth; use yii\filters\auth\HttpBearerAuth;
use yii\filters\auth\QueryParamAuth; use yii\filters\auth\QueryParamAuth;
@ -59,11 +60,21 @@ class ProfileController extends \yii\rest\Controller
public function actionAddToInterview() public function actionAddToInterview()
{ {
if (\Yii::$app->request->isPost) { if (\Yii::$app->request->isPost) {
$attributes = \Yii::$app->request->post();
$model = new InterviewRequest(); $model = new InterviewRequest();
$model->attributes = \Yii::$app->request->post(); $model->attributes = $attributes;
$model->created_at = time(); $model->created_at = time();
$model->user_id = \Yii::$app->user->id; $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']}\nEmail: {$attributes['email']}\nКомментарий: {$attributes['comment']}";
$bot = new TelegramBotService($token);
$bot->sendMessageTo($chat_id, $message);
return ['status' => 'success']; return ['status' => 'success'];
} }