kielabokkie/aws-pinpoint-laravel-notification-channel

v0.2.0 2020-11-07 02:58 UTC

This package is auto-updated.

Last update: 2024-09-07 10:46:17 UTC


README

Latest Version on Packagist Software License Build Status StyleCI Quality Score Code Coverage Total Downloads

本包简化了使用 AWS Pinpoint(AwsPinpoint)在 Laravel 5.5+ 和 6.0 中发送通知的过程。

注意:目前仅支持短信。其他消息类型,如语音和电子邮件,将在后续版本中提供。如果您想帮助开发这些功能,请与我们联系。

使用 AWS Pinpoint 简单地发送短信。

内容

安装

您可以通过运行以下命令使用 composer 安装此包:

composer require kielabokkie/aws-pinpoint-laravel-notification-channel

设置 AwsPinpoint 服务

此包使用 AWS 服务提供者 Laravel 包。您需要在您的 config/aws.php 文件中添加 AWS Pinpoint 的特定配置。以下是一个示例:

...
'Pinpoint' => [
    'region' => env('AWS_PINPOINT_REGION'),
    'application_id' => env('AWS_PINPOINT_APPLICATION_ID'),
    'sender_id' => env('AWS_PINPOINT_SENDER_ID'),
    'key' => env('AWS_PINPOINT_KEY'),
    'secret' => env('AWS_PINPOINT_SECRET'),
],
...

然后,在您的 .env 文件中添加以下条目:

...
AWS_PINPOINT_REGION=
AWS_PINPOINT_APPLICATION_ID=
AWS_PINPOINT_SENDER_ID=
AWS_PINPOINT_KEY=
AWS_PINPOINT_SECRET=
...

用法

一切设置完毕后,您可以按照以下方式发送通知:

<?php

namespace App\Notifications;

use App\User;
use Illuminate\Notifications\Notification;
use NotificationChannels\AwsPinpoint\AwsPinpointChannel;
use NotificationChannels\AwsPinpoint\AwsPinpointSmsMessage;

class PhoneVerificationCreated extends Notification
{
    /**
     * Get the notification's delivery channels.
     *
     * @param \App\User $notifiable
     * @return array
     */
    public function via(User $notifiable)
    {
        return [AwsPinpointChannel::class];
    }

    /**
     * Send SMS via AWS Pinpoint.
     *
     * @param \App\User $notifiable
     * @return \NotificationChannels\AwsPinpoint\AwsPinpointSmsMessage
     */
    public function toAwsPinpoint(User $notifiable)
    {
        $message = sprintf('Your order %s has been dispatched', $this->orderId);

        return (new AwsPinpointSmsMessage($message))
            ->setRecipients($notifiable->mobile_number);
    }
}

更新日志

有关最近更改的详细信息,请参阅 更新日志

测试

$ composer test

安全性

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

贡献

有关详细信息,请参阅 贡献

致谢

许可协议

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