custom-pages icon indicating copy to clipboard operation
custom-pages copied to clipboard

Simple custom notifications?

Open Mazvy opened this issue 4 years ago • 3 comments

Is it possible to initiate a notification (web & email) to a user without resorting to creating a full fledged model for that?

I'd like to send a basic notification consisting of for example:

array(
  "recipientUserId" => 123,
  "message" => "Report for X finished generating!",
  "link" => "https://link.to.report/for?user=x"
);

It's unclear to me if that's possible without a custom module?

Mazvy avatar Feb 17 '21 08:02 Mazvy

Currently you need a separate class for each Notification type. This must be provided by a custom module. It would be conceivable, for example, to create the possibility of triggering generic notifications via the REST module.

luke- avatar Feb 17 '21 10:02 luke-

Currently you need a separate class for each Notification type. This must be provided by a custom module. It would be conceivable, for example, to create the possibility of triggering generic notifications via the REST module.

So as it stands, there is no real way of triggering custom notifications without requiring a model?

I'm trying to externally piggyback of an existing model like admin notifications or something, but I'm not following the logic here at all. The farthest I got was to initiate a notification without an error but then the cronjob fails with

Could not execute queued job! Message: Class __PHP_Incomplete_Class has no unserializer

I understand this is not how Yii or Humhub works, but I just need a simple notification sent from my custom page ... Here's my "attempt" that spits out the above error.

namespace humhub\modules\admin\notifications;

require dirname(__FILE__).'/../protected/vendor/autoload.php';
require dirname(__FILE__).'/../protected/vendor/yiisoft/yii2/Yii.php';

$config = \yii\helpers\ArrayHelper::merge(
    require(__DIR__ . '/../protected/humhub/config/common.php'),
    require(__DIR__ . '/../protected/humhub/config/web.php'),
    (is_readable(__DIR__ . '/../protected/config/dynamic.php')) ? require(__DIR__ . '/../protected/config/dynamic.php') : [],  
);
new \humhub\components\Application($config);

use yii\helpers\Url;
use humhub\modules\user\models\User;
use humhub\modules\notification\components\BaseNotification;

class TestNotification extends BaseNotification {

    public $moduleId = 'admin';

    public $requireOriginator = false;
    public $requireSource = false;

    public function getUrl() {
        return Url::to(['/some/test/url']);
    }

    public function html() {
        return Yii::t('AdminModule.notification', 'Testing 123');
    }

}

$getUser = User::findIdentity(123456789);
TestNotification::instance()->send($getUser);

Mazvy avatar Feb 17 '21 22:02 Mazvy

I don't think, this will be possible without a custom module.

For a prototype, I would recommend that you simply create a Sekeleton module, activate the module and test the notification there. https://docs.humhub.org/docs/develop/modules#setup-a-module-skeleton

luke- avatar Feb 18 '21 09:02 luke-