asasem/laravel-vk-notification-channel

0.0.1 2023-05-02 19:54 UTC

This package is auto-updated.

Last update: 2024-10-03 09:48:19 UTC


README

本包使您能够使用Laravel 5.3轻松通过vk.com发送通知。

内容

安装

您可以通过composer安装此包

composer require enniel/laravel-vk-notification-channel

用法

现在您可以在通知内的via()方法中使用该通道

use NotificationChannels\Vk\VkChannel;
use NotificationChannels\Vk\VkMessage;
use Illuminate\Notifications\Notification;

class ExampleNotification extends Notification
{
    public function via($notifiable)
    {
        return [VkChannel::class];
    }

    public function toVkontakte($notifiable)
    {
        return (new VkMessage())
            ->message('message text')
            ->token('some_token');
    }
}

为了让您的通知知道向谁发送消息,您必须将routeNotificationForVkontakte方法添加到通知模型中,该方法返回类似['user_id', 1]的数组数据。

可用消息方法

  • user():用户ID(默认为当前用户)。接受参数user_id
  • random():唯一的标识符,用于避免重新发送消息。接受参数random_id
  • peer():目标ID。接受参数peer_id
  • domain():用户的简短地址(例如,illarionov)。接受参数domain_id
  • chat():与消息相关的会话ID。接受参数chat_id
  • users():消息接收者的ID(如果需要开始新的对话)。接受参数user_ids
  • message():发送者的身份。接受参数message
  • lat():签到点的地理纬度,单位为度(从-90到90)。接受参数lat
  • long():签到点的地理经度,单位为度(从-180到180)。接受参数long
  • attachment():附加到消息的对象列表。接受参数attachment
  • forwarded():转发消息的ID。接受参数forward_messages
  • sticker():贴纸ID。接受参数sticker_id
  • notification()1true,如果消息是通知(对于社区消息)。接受参数notification
  • token():访问令牌。传递参数access_token。更多信息请参阅授权获取令牌
  • to():接收者。接受数组,如['user_id', 1],其中第一个值对应以下之一:peer_id、user_id、domain、chat_id或user_ids。

有关参数的更多信息,请参阅messages.send

测试

$ composer test

致谢

许可

MIT许可(MIT)。有关更多信息,请参阅许可文件