Integration yii2-extenstion for telegram bot service

This commit is contained in:
Korzinkayablok 2021-08-27 12:35:22 +03:00
parent 83e1659632
commit 0a39cc750a
5 changed files with 1895 additions and 579 deletions

2
.gitignore vendored
View File

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

View File

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

2440
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -77,6 +77,17 @@ return [
['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,

View File

@ -69,23 +69,7 @@ class ProfileController extends \yii\rest\Controller
$model->user_id = \Yii::$app->user->id;
if ($model->save()) {
$token = \Yii::$app->params['telegramBotToken'];
$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);
\Yii::$app->telegram_bot->sendRenderedMessage('interview_request', $attributes);
return ['status' => 'success'];
}