karix/karix-notification

允许您将karix短信和WhatsApp作为自定义通道用于Laravel通知

1.0.1 2020-07-06 13:21 UTC

This package is auto-updated.

Last update: 2024-09-06 22:19:59 UTC


README

此包使您能够通过Karix.io轻松使用Laravel 6发送短信。

安装

您可以通过Composer安装此包

composer require karix/karix-notification

设置Karix ID和Token

登录Karix.io并获取您的ID和Token,将其放在您的.env文件中,并将您的Karix ID和Token添加到config/services.php

// config/karix.php
<?php
    return [
        'id'            => env('KARIX_ID'),
        'token'         => env('KARIX_TOKEN'),
        'sms_from'      => env('KARIX_FROM'),
        'whatsapp_from' => env('KARIX_WHATSAPP')
    ];

用法

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

use KarixTech\Karix\Broadcasting\KarixMessage;
use KarixTech\Karix\Broadcasting\KarixSMSChannel;
use KarixTech\Karix\Broadcasting\KarixWhatsappChannel;


class YourNotification extends Notification
{
    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [KarixSMSChannel::class, KarixWhatsappChannel::class];
    }


    public function toSmSKarix($notifiable)
    {
        return KarixMessage::create()
            ->content(['text' => 'Your message comes here']);
    }

    public function toWhatsappKarix($notifiable)
    {
        return KarixMessage::create()
            ->content([
                'text' => 'Your message comes here',
                'media' => 'url-to-media',
                'location' => [
                    'latitude' => 'the latitude here',
                    'longitude' => 'the longitude here'
                ]
            ]);
    }
}

为了使通知知道有一个名为KarixSmsChannel的新通道,请将routeNotificationForKarix方法添加到您的Notifiable模型中(可能是您的user.php文件)。

此方法需要返回用户的电子邮件(如果是私人板)和要添加卡的Trello列表的ID列表。

注意:请确保您的表中有一个'phone'字段,以及您要使用的国家代码,如+91xxxxxxxxxx。

public function routeNotificationForKarix()
{
    return $this->phone;
}

安全

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

贡献

有关详细信息,请参阅CONTRIBUTING

致谢

许可

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