问题描述
我正在尝试通过 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 (将#修改为@)