mirkhamidov/yii2-notifications
Composer 安装命令:
composer require mirkhamidov/yii2-notifications
包简介
Notifications system
README 文档
README
- configure
componentsfrom module - configure
queueNotificationfrom module - add requirements in composer.json
- slack notifications
- email notifications
Notification providers
Telegram
description see below, in examples
Default Yii2 Mailer
configure in main config file main.php
return [
'modules' => [
...
'notifications' => [
'class' => mirkhamidov\notifications\Module::class,
'queueIn' => 'queueNotifications',
'providers' => [
...
'default-mailer' => [
'class' => MailerProvider::class,
'from' => [{SENDER EMAIL} => {SENDER NAME}],
],
],
],
],
];
send using view file and view params
Yii::$app->notifications->sendTemplateMail([
'to' => {RECEPIENT EMAIL},
'subject' => {SUBJECT},
'view' => ['html' => {HTML VIEW}, 'text' => {TEXT VIEW}],
'params' => [
{KEY-VALUE params for views}
],
]);
or already rendered/prepared text and other params
Yii::$app->notifications->sendTemplateMail([
'to' => {RECEPIENT EMAIL},
'subject' => 'Test messages fo ' . rand(1, 99999),
'htmlBody' => $msg,
['textBody' => $msg,]
['cc' => {CC},]
['bcc' => {BCC},]
['replyTo' => {REPLY TO EMAIL},]
['attachFilePath' => {PATH TO FILE TO ATTACH},]
]);
Configuration
in main app config file
return [ 'bootstrap' => [ 'queueNotifications', ], 'components' => [ 'queueNotifications' => [ 'class' => \yii\queue\db\Queue::class, 'as log' => \yii\queue\LogBehavior::class, 'db' => 'db', // DB connection component or its config 'tableName' => '{{%queue}}', // Table name 'channel' => 'notification', // Queue channel key 'mutex' => \yii\mutex\PgsqlMutex::class, // Mutex that used to sync queries 'mutexTimeout' => 0, 'ttr' => 5 * 60, // Max time for anything job handling 'attempts' => 5, // Max number of attempts ], 'notifications' => [ 'class' => \mirkhamidov\notifications\Notifications::class, ], ], 'modules' => [ 'notifications' => [ 'class' => mirkhamidov\notifications\Module::class, 'queueIn' => 'queueNotifications', 'providers' => [ 'telegram' => [ 'class' => \mirkhamidov\notifications\providers\Telegram::class, ], ], ], ], ];
Logs to different file
In app config file
'components' => [
'log' => [
'targets' => [
...
[
'class' => 'yii\log\FileTarget',
'categories' => [
'mirkhamidov\notifications\providers\*',
],
'logFile' => '@app/runtime/logs/notification-providers.log',
'logVars' => [],
'prefix' => function ($message) {
return '';
}
],
],
],
],
Examples
Telegram Send message
use mirkhamidov\notifications\providers\TelegramProvider;
$msg = 'any message';
\Yii::$app->notifications->send($msg, TelegramProvider::ID, [
'providerParams' => [
'chat_id' => {CHAT_ID},
],
]);
More providerParams look at Telegram SendMessage API
Telegram Message with file
use mirkhamidov\notifications\providers\TelegramProvider;
$msg = 'any message';
\Yii::$app->notifications->send($msg, TelegramProvider::ID, [
'providerParams' => [
'chat_id' => Yii::$app->params['telegram']['miroff'],
'file' => $model->getPdfFilePath(),
'fileParams' => [
// custom params
['fileType' => TelegramProvider::FILE_TYPE_DOCUMENT,]
['messageMergeType' => TelegramProvider::FILE_MESSAGE_MERGE_TYPE_AS_REPLY,]
// any other Telegram API params, see below
['disable_notification' => true,]
],
],
]);
filefull path to filefileParamsparams to manage with filemessageMergeType- TelegramProvider::FILE_MESSAGE_MERGE_TYPE_AS_NO_MERGE default send message and file as separate messages
- TelegramProvider::FILE_MESSAGE_MERGE_TYPE_AS_REPLY send file as reply for sent message
fileType- TelegramProvider::FILE_TYPE_DOCUMENT default Telegram API for more params
- TelegramProvider::FILE_TYPE_PHOTO Telegram API for more params
- TelegramProvider::FILE_TYPE_AUDIO Telegram API for more params
- TelegramProvider::FILE_TYPE_VIDEO Telegram API for more params
To send only file (without message) just set $mgs to null
mirkhamidov/yii2-notifications 适用场景与选型建议
mirkhamidov/yii2-notifications 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 47 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 06 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「module」 「notifications」 「yii2」 「telegram」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mirkhamidov/yii2-notifications 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mirkhamidov/yii2-notifications 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mirkhamidov/yii2-notifications 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova package that adds a notification feed in your Nova app.
A custom URL rule class for Yii 2 which allows to create translated URL rules
bootstrap select field module implementing http://silviomoreto.github.io/bootstrap-select/
Captures outgoing SMS notifications
SCEditor, a lightweight WYSIWYG BBCode & HTML editor extension for Yii 2.0 Framework
Yii2 module to manage website content. Kind of a CMS...
统计信息
- 总下载量: 47
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2018-06-02