superbalist/laravel-appboy

此包已被弃用且不再维护。未建议替代包。

一个用于通过 Appboy API 发送推送通知的 Laravel 库

1.0.0 2017-05-30 11:46 UTC

This package is auto-updated.

Last update: 2022-08-04 13:26:45 UTC


README

一个通过 Appboy API 发送推送通知的 Laravel 库

Author Build Status StyleCI Software License Packagist Version Total Downloads

此包是一个连接 php-appboy 到 Laravel 的包装器。

安装

composer require superbalist/laravel-appboy

在 app.php 中注册服务提供者

'providers' => [
    // ...
    Superbalist\LaravelAppboy\AppboyServiceProvider::class,
]

在 app.php 中注册外观

'aliases' => [
    // ...
    'Appboy' => Superbalist\LaravelAppboy\AppboyFacade::class,
]

该包有一个默认配置,使用以下环境变量。

APPBOY_APP_GROUP_ID=null
APPBOY_API_URI=https://api.appboy.com

要自定义配置文件,请使用 Artisan 发布包配置。

php artisan vendor:publish --provider="Superbalist\LaravelAppboy\AppboyServiceProvider"

然后您可以编辑生成的配置,在 app/config/appboy.php

使用

use Appboy;
use Superbalist\Appboy\NotificationBuilder;
use Superbalist\Appboy\ScheduledNotificationBuilder;
use Superbalist\Appboy\Messages\AndroidMessageBuilder;
use Superbalist\Appboy\Messages\AppleMessageBuilder;

// send a push message
Appboy::sendMessage(
    (new NotificationBuilder())
        ->toUsers([1, 2])
        ->setCampaign('my_campaign')
        ->ignoreFrequencyCapping()
        ->setSubscriptionState('opted_in')
        ->withMessages([
            'apple_push' => (new AppleMessageBuilder())
                ->setAlert('Hello World!')
                ->setSound('custom_sound')
                ->withExtraAttributes(['is_test' => true])
                ->setCategory('shipping_notification')
                ->expiresAt(new \DateTime('2017-05-29 10:00:00', new \DateTimeZone('Africa/Johannesburg')))
                ->setUri('http://superbalist.com')
                ->setMessageVariation('group_a')
                ->setAsset('file://image.jpg', 'jpg')
                ->build(),
            'android_push' => (new AndroidMessageBuilder())
                ->setAlert('Hello World!')
                ->setTitle('Message Title')
                ->withExtraAttributes(['is_test' => true])
                ->setMessageVariation('group_a')
                ->setPriority(2)
                ->setCollapseKey('shipment_1234')
                ->setSound('custom_sound')
                ->setUri('http://superbalist.com')
                ->setSummaryText('This is a summary line')
                ->setTimeToLive(60)
                ->setNotificationId(18456)
                ->setPushIconImageUrl('http://link/to/asset.jpg')
                ->setAccentColour(16777215)
                ->build(),
        ])
        ->build()
);

// schedule a push message
Appboy::scheduleMessage(
    (new ScheduledNotificationBuilder())
        ->toUsers([1, 2])
        ->setCampaign('my_campaign')
        ->ignoreFrequencyCapping()
        ->setSubscriptionState('opted_in')
        ->withMessage(
            'apple_push',
            (new AppleMessageBuilder())
                ->setAlert('Hello World!')
                ->setSound('custom_sound')
                ->withExtraAttributes(['is_test' => true])
                ->setCategory('shipping_notification')
                ->expiresAt(new \DateTime('2017-05-29 10:00:00', new \DateTimeZone('Africa/Johannesburg')))
                ->setUri('http://superbalist.com')
                ->setMessageVariation('group_a')
                ->setAsset('file://image.jpg', 'jpg')
                ->build()
        )
        ->sendsAt(new \DateTime('2017-05-29 10:00:00', new \DateTimeZone('Africa/Johannesburg')))
        ->build()