Merge pull request #50 from apuc/telegram-bot-notification

Interview telegram bot notification
This commit is contained in:
kavalar 2021-08-25 12:44:17 +03:00 committed by GitHub
commit 111d9094c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 4 deletions

2
.gitignore vendored
View File

@ -22,7 +22,7 @@ Thumbs.db
# composer itself is not needed
composer.phar
composer.lock
# Mac DS_Store Files
.DS_Store

View File

@ -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",

View File

@ -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'];
}