Merge pull request #52 from apuc/telegram-bot-extension

Yii2 telegram bot extension integration as component
This commit is contained in:
kavalar 2021-08-27 12:50:29 +03:00 committed by GitHub
commit 3b705f1cd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 19 deletions

2
.gitignore vendored
View File

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

View File

@ -32,7 +32,8 @@
"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.2.0" "kavalar/telegram_bot": "^0.2.0",
"kavalar/yii2-telegram-bot": "^0.1.0"
}, },
"require-dev": { "require-dev": {
"yiisoft/yii2-debug": "~2.0.0", "yiisoft/yii2-debug": "~2.0.0",

View File

@ -77,6 +77,17 @@ return [
['class' => 'yii\rest\UrlRule', 'controller' => 'skills'], ['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, 'params' => $params,

View File

@ -69,23 +69,7 @@ class ProfileController extends \yii\rest\Controller
$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']; \Yii::$app->telegram_bot->sendRenderedMessage('interview_request', $attributes);
$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);
return ['status' => 'success']; return ['status' => 'success'];
} }