enniel/laravel-vk-notification-channel

v0.0.2 2016-10-25 08:52 UTC

This package is auto-updated.

Last update: 2024-09-06 03:59:17 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)。有关更多信息,请参阅 许可文件