tuyakhov / yii2-notifications Goto Github PK
View Code? Open in Web Editor NEWThis Yii2 extension provides support for sending notifications across a variety of delivery channels, including mail, SMS, Slack, Telegram etc.
This Yii2 extension provides support for sending notifications across a variety of delivery channels, including mail, SMS, Slack, Telegram etc.
Looks like this plugin has been inspired from Lavavel's notification. Can we also add database notification which is critical to show notifications in web interface?
https://laravel.com/docs/5.3/notifications#database-notifications
Now it is:
public $apiUrl = "https://api.telegram.org/";
There is a redundant trailing slash which cause an error of API request.
Now, for fixing it, I override it with a config value without a trailing slash.
If I specify a subject to a MailMessage, the sent mail does not have a subject, because the subject is not passed to the mailer.
In order to fix this issue, you have to specify the subject at MailChannel.php during compose.
->setSubject($message->subject)
The default class included is named Notification. It fails out of the box.
THIS IS A PROBLEM OF THE RELEASE 1.1.0
A per the current read me, the interface methods exportForMail() and exportForSms() do not exist but what is available is the exportFor($channel) function which expects the channel parameter and the broadcastOn() functions.
This document does not reflect on the current modifications and because of that setting it up is a problem. So please update it coz I really need to use your great extension, just not certain how to. FYI examples on using the database channel would greatly help.
Error message when yii migrate execute:
create table notification ...Exception 'yii\db\Exception' with message 'SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'created_at'
Solved by adding default value to migration:
@vendor/tuyakhov/yii2-notifications/src/migrations
...
'created_at' => $this->timestamp()->null(),
...
PHP 7.2.10-0ubuntu0.18.04.1 (cli)
MySQL 5.7.23-0ubuntu0.18.04.1 (Ubuntu)
Find this issue when applying batch action...
Try to send notifications like this:
Yii::$app->notifier->send($user1, $notification1);
Yii::$app->notifier->send($user1, $notification2);
Yii::$app->notifier->send($user2, $notification3);
I know that notifications may sending in array... But it is impossible in some use cases.
Right now, if many noty sending in this way, second query (and the following) in ActiveRecordChannel.php loads Existing Model! And we do insert() function on Existing model!
In my project this issue do not sending some data in Database ONLY in batch insert (there is some other fields in DB, since i use a different ActiveRecordChannel):
My solution is to create new Model before load Data (Change in ActiveRecordChannel.php from line 46):
$class = $this->model;
$model = \Yii::createObject($class::className());
if ($model->load($data, '')) {
return $model->insert();
}
This issue need to checking by contributors, since i use extending ActiveRecordChannel. But inserting on existing Model is not right way.
See #10
ActiveRecordInterface::insert
does not use second param as an input of values, it only filter which properties must be allowed.
ActiveRecordChannel should have method send like this:
public function send(NotifiableInterface $recipient, NotificationInterface $notification)
{
/** @var DatabaseMessage $message */
$message = $notification->exportFor('database');
list($notifiableType, $notifiableId) = $recipient->routeNotificationFor('database');
$this->model->level = $message->level;
$this->model->subject = $message->subject;
$this->model->body = $message->body;
$this->model->notifiable_type = $notifiableType;
$this->model->notifiable_id = $notifiableId;
return $this->model->insert(true);
}
Migration is not working, and it is because yii migrator is expecting a file with a custom name convention m000000_000000_XXXXXX
Cant find in doc , please add it ,Thank you!
Hi , I have error when execute yii migrate
it's caused by namespace of the migration.
Please add this line
namespace tuyakhov\notifications\migrations;
in m180824_090744_create_notification_table.php
Thanks!!
Regards
Hi, I have added some features to your project, but maybe they are out of the scope of this project.
Would you be interested on reviewing them and then asses if I should go for a new project or upgrade yours?
Add support for URL storing for notifications in database. I think it is good feature for this awesome extension. Need to update Notification Model class.
Right now the solution is parsing $body attribute for storing url, for example:
$notification->body = "/some/url||message";
...
$urlMessage = explode('||', $notification->body, 2);
$url = count($urlMessage) == 2 ? $urlMessage[0] : null;
$message = count($urlMessage) == 2 ? $urlMessage[1] : $urlMessage[0];
It would be great if you could show an example of how we can use the package with a socket (ex. notification).
Yii version: 2.0.14
Error using "database" channel:
Unknown Method โ yii\base\UnknownMethodException
Calling unknown method: yii\db\ActiveQuery::addOnCondition()
tuyakhov/yii2-notifications/src/NotifiableTrait.php at line 73 and 78:
public function getNotifications()
{
/** @var $this BaseActiveRecord */
return $this->hasMany(Notification::className(), ['notifiable_id' => 'id'])
->addOnCondition(['notifiable_type' => get_class($this)]);
}
public function getUnreadNotifications()
{
return $this->getNotifications()->addOnCondition(['read_at' => null]);
}
Solved by rename method to "onCondition()". Is it yii2 version specified or not?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.