Merge pull request #51 from apuc/telegambot-notification-templates

Interview request notification by Telegram bot  using template processor
This commit is contained in:
kavalar 2021-08-25 18:14:00 +03:00 committed by GitHub
commit 83e1659632
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View File

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

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\BotNotificationTemplateProcessor;
use kavalar\TelegramBotService; use kavalar\TelegramBotService;
use yii\filters\auth\CompositeAuth; use yii\filters\auth\CompositeAuth;
use yii\filters\auth\HttpBearerAuth; use yii\filters\auth\HttpBearerAuth;
@ -71,12 +72,17 @@ class ProfileController extends \yii\rest\Controller
$token = \Yii::$app->params['telegramBotToken']; $token = \Yii::$app->params['telegramBotToken'];
$chat_id = \Yii::$app->params['telegramBotChatId']; $chat_id = \Yii::$app->params['telegramBotChatId'];
$message = $templates = [
"Пришёл запрос на интервью.\n". 'interview_request' =>
"Профиль: {$attributes['profile_id']}\n". "Пришёл запрос на интервью.\n".
"Телефон: {$attributes['phone']}\n". "Профиль: ~profile_id~\n".
"Email: {$attributes['email']}\n". "Телефон: ~phone~\n".
"Комментарий: {$attributes['comment']}"; "Email: ~email~\n".
"Комментарий: ~comment~"
];
$templateProcessor = new BotNotificationTemplateProcessor($templates);
$message = $templateProcessor->renderTemplate('interview_request', $attributes);
$bot = new TelegramBotService($token); $bot = new TelegramBotService($token);
$bot->sendMessageTo($chat_id, $message); $bot->sendMessageTo($chat_id, $message);