Octobercms 插件中的电报通知

Telegram notifications in Octobercms plugin

我想使用 laravel 的电报通知渠道向 17:00 的特定用户发送电报消息,但我似乎无法继续进行。我目前使用 cmd 命令进行测试,但不断出现错误并且不知道该怎么做。

这是我的命令和通知文件:

SendNotification.php

<?php

namespace Rogier\Lab\Console;

use Illuminate\Console\Command;
use Rogier\Lab\Notifications\DailyTelegram;

   class SendNotifications extends Command
   {

    protected $name = 'lab:notifications:send';
    protected $description = 'Send notifications';
    protected $userid = 919871501;

    /**
     * Execute the console command.
     * @return void
     */
    public function handle()
    {   
        $this->output->writeln('Sending notifications');
        $notification =  new DailyTelegram($this->userid);
        $notification->via()->toTelegram();
        $this->output->writeln('Done');
    }


}

和DailyTelegram.php

<?php

namespace Rogier\Lab\Notifications;

use NotificationChannels\Telegram\TelegramChannel;
use NotificationChannels\Telegram\TelegramMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Notifiable;


class DailyTelegram extends Notification
{

    protected $userid = 919871501;


    public function via()
    {
        return [TelegramChannel::class];
    }

    public function toTelegram()
    {
        return TelegramMessage::create()
            // Optional recipient user id.
            ->to($this->userid)
            // Markdown supported.
            ->content("Hello there!\nYour invoice has been *PAID*");
    }
}

我目前收到错误 "Call to a member function toTelegram() on array",但我觉得我尝试了所有方法,也许我做的完全错了。有谁知道我应该怎么做?

提前致谢

是的,你做错了。 Notifiables 有 notify() 方法,你应该使用它:

$user->notify(new DailyTelegram);

在此示例中,$userApp\User 实例(开箱即用)。

您应该查看两个 Laravel's sending notifications and laravel-notification-channels/telegram 文档。