Merge pull request #52 from apuc/telegram-bot-extension
Yii2 telegram bot extension integration as component
This commit is contained in:
commit
3b705f1cd5
2
.gitignore
vendored
2
.gitignore
vendored
@ -22,7 +22,7 @@ Thumbs.db
|
||||
|
||||
# composer itself is not needed
|
||||
composer.phar
|
||||
composer.lock
|
||||
/composer.lock
|
||||
# Mac DS_Store Files
|
||||
.DS_Store
|
||||
|
||||
|
@ -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": "^0.1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"yiisoft/yii2-debug": "~2.0.0",
|
||||
|
@ -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,
|
||||
|
@ -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'];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user