teurons/neptune-php

Neptune 的 PHP 辅助工具

dev-master 2022-06-01 14:53 UTC

This package is auto-updated.

Last update: 2024-08-29 05:37:38 UTC


README

Neptune 是一个托管的事件驱动的外部通信系统,包括事件分析。

您可以向 Neptune 发送事件,并对其进行响应以处理电子邮件、短信、推送通知和应用/仪表板通知。

步骤 1

  • 在 Neptune 中创建一个团队
  • 创建一个 API 令牌
  • 创建一个 dev 环境,并将其标记为模拟

步骤 2

使用 Composer 安装 PHP SDK

composer require teurons/neptune-php

步骤 3

在您的 .ENV 中配置以下内容

NEPTUNE_ENV=dev
NEPTUNE_TOKEN=<paste_your_api_token_here>

这样,您就配置好了 Neptune。

用法

发送事件

    $neptune = new Neptune();

    $eventType = "login_with_otp";
    $eventData = [
            'otp' => 123456
    ];
    $neptuneData = [
        'user_id' => '343-4324-23432',
        'contact_infos => [
            ['type' => 'email', 'value' => 'rajiv@example.com'],
            ['type' => 'mobile_number', 'value' => '+1XXXXXXXX']
        ]
    ];

    $neptune->fire(
        $eventType,
        $eventData,
        $neptuneData
    );
  • $eventType - 它可以是任何字符串,您可以遵循任何约定。在上面的例子中,我们使用了由下划线分隔的、小写字母数字字符。
  • $eventData - 数据是可选的,可以是一个空数组。实际上,这些数据会发送到您的模板中,以便将发送给用户的通信动态化。数组中的键将用于预填充模板数据,如果您在电子邮件/短信模板中使用了如 {{ otp }} 这样的变量。
  • $neptuneData - 您可以使用 Neptune 数据发送 user_id、联系信息等。您可以在以下位置查看可用的 contactTypes:[https://teurons.com/docs/neptune/usage/contact-types](https://teurons.com/docs/neptune/usage/contact-types)

读取应用通知

您可以读取应用通知,您可以在应用的通知部分向用户展示。

    $neptune = new Neptune();

    $userId = 1;

    $notifications = $neptune->appNotificationsGet($userId, [
        "type" => "unread"
    ]);

可能存在三种类型:all、unread、read

默认为 "unread"。

将通知标记为已读

您可以标记一条特定的通知为已读。

    $neptune = new Neptune();

    $type = "notification";
    $identifier = "191df352-5eb6-4e92-a0a2-912a485eb7c7";

    $notifications = $neptune->appNotificationMarkAsRead($type,$identifier);

将用户的所有通知标记为已读

    $neptune = new Neptune();

    $type = "user";
    $identifier = "1";

    $notifications = $neptune->appNotificationMarkAsRead($type,$identifier);

Laravel

use Teurons\Neptune\NeptuneChannel;

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


    public function toNeptune($notifiable)
    {
        return [
            'event_type' => 'user_requested_to_reset_password',
            'data' => [
                'token' => 123456
            ],
            'user_id' => $notifiable->id,
            "contact_infos" => [
                [
                    "type" => "email",
                    "value" => $notifiable->email
                ]
            ],
        ];
    }

}