微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

未向 RocketChat 发送 Laravel 通知

如何解决未向 RocketChat 发送 Laravel 通知

我正在尝试通过 laravel 向 Rocketchat 发送通知,但我遇到了一些问题。我一直在关注这个网站:https://laravel-notification-channels.com/rocket-chat/#contents

这是我的通知类:

use Illuminate\Notifications\Notification;
use NotificationChannels\RocketChat\RocketChatMessage;
use NotificationChannels\RocketChat\RocketChatWebhookChannel;

    class FailureAlarm extends Notification
    {
        public function via($notifiable)
        {
            return [
                RocketChatWebhookChannel::class,];
        }
    
        public function toRocketChat($notifiable)
        {
            return RocketChatMessage::create('Sample Notification')
                ->to('channel name')
                ->content('Sample Notification test.');
        }
    
        public function routeNotificationForRocketChat()
        {
            return 'channel-name';
        }
    }

所以困惑是当我需要发送通知时如何调用这个类。 我的 env 文件中有这些,可通过配置访问:

'rocketchat' => [
    'url' => env('ROCKETCHAT_URL'),'token' => env('ROCKETCHAT_TOKEN'),'channel' => env('ROCKETCHAT_CHANNEL'),],

其中 url 是 webhook URL,channel 是要发送通知的房间或组。我已经尝试过使用通知门面的正常方法,例如:

    $hook = Config::get('services.rocketchat.url');
    Notification::send($hook,new FailureAlarm($notificationData));

以及带有匿名通知的按需通知,例如:

Notification::route('rocketchat',$hook)
            ->notify(new FailureAlarm($notificationData));

在后一种方法中,我尝试通过 $hook 发送频道名称、webhook url 和令牌,但无济于事。此外,我已经注册了事件监听器来记录发送、发送和失败的事件。事件侦听器总是显示 sending!sent!,而实际上 Rocketchat 中没有消息。我在逻辑上做了什么破事吗?还是配置中遗漏了什么?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。