helliomessaging/helliomessaging-laravel-notification-channel

Helliomessaging 通知通道,适用于 Laravel 5.3+

v1.4 2024-03-18 16:18 UTC

README

Latest Stable Version Total Downloads License

此包使您能够轻松使用Hellio Messaging发送通知

内容

安装

要获取 Hellio Messaging 通知通道的最新版本,适用于 Laravel 5.5 及以上版本,只需使用 Composer 安装项目。

composer require helliomessaging/helliomessaging-laravel-notification-channel

如果您使用 Laravel 5.5+,则不需要以下步骤。如果不行,安装包后,您需要注册服务提供者。打开 config/app.php 并将以下内容添加到 providers 键中。

  • NotificationChannels\Hellio\HellioServiceProvider::class

设置 Hellio Messaging 服务

首先,您必须在 Hellio 上有一个账户。一旦您注册了账户,请登录您的账户,然后点击 Hellio Messaging 控制面板上的 个人资料 & API 集成 菜单。点击 API 密钥 & Webhooks 选项卡,复制您的 客户端 ID应用程序密钥

在终端运行

php artisan vendor:publish --provider="NotificationChannels\Hellio\HellioServiceProvider"

这将在您的 config 目录中创建一个 hellio.php 文件。

将您的 API 密钥粘贴到 config/hellio.php 配置文件中。您可以将下面的示例配置复制过来以开始使用

<?php

return [
    'config' => [
        'client_id' => env('HELLIO_CLIENT_ID'),
        'app_secret' => env('HELLIO_APP_SECRET')
    ],

];

或者

HELLIO_CLIENT_IDHELLIO_APP_SECRET 添加到您的 .env 文件中

用法

现在您可以在任何使用 Hellio Messaging 发送的通知的 via() 方法中使用该通道

<?php

use Illuminate\Notifications\Notification;
use NotificationChannels\Hellio\HellioChannel;
use NotificationChannels\Hellio\HellioMessage;

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

    public function toHellioSMS($notifiable)
    {
        return (new HellioMessage)
   ->from("HellioSMS")
   ->to("233242813656") //Add the country code to the number you wish to send to without the need to add the  +
              ->content("Welcome to Hellio Messaging, a new world of litmitless possibilities.")
              ->messageType(0); //0 = text, 1 = flash
    }
}

为了使您的通知知道您要发送到哪个电话号码,请将 routeNotificationForHellioSMS 方法添加到您的可通知模型中,例如您的用户模型

public function routeNotificationForHellioSMS()
{
    return $this->phone; // where phone is a column in your users table;
}

可用的消息方法

  • from($from) : 设置发送者的 id
  • senderID($id): from($from) 的别名
  • to($to) : 设置收件人的电话号码
  • msisdn($msisdn): to($to) 的别名
  • messageType($messageType): type($type) 的别名
  • content($content) : 设置消息内容
  • message($message): content($content) 的别名

有关可用方法的更多信息,请参阅 Hellio Messaging 文档门户

测试

composer test

安全

如果您发现任何安全相关的问题,请通过电子邮件support@helliomessaging.com联系,而不是使用问题跟踪器。

贡献

有关详细信息,请参阅CONTRIBUTING

致谢

许可证

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