zhuk / laravel-intercom
Laravel 中的 Intercom 客户端和通知
v1.0.0-alpha.2
2021-10-13 01:52 UTC
Requires
- php: ^7.4|^8.0
- illuminate/notifications: ~6.0 || ~7.0 || ~8.0
- illuminate/support: ~6.0 || ~7.0 || ~8.0
- intercom/intercom-php: ^4.4
- php-http/guzzle7-adapter: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.2
- phpro/grumphp: ^1.5
- vimeo/psalm: ^4.10
This package is auto-updated.
Last update: 2024-09-13 14:49:53 UTC
README
Laravel 通知驱动和 PHP Intercom API 绑定
安装
通过 composer
composer require zhuk/laravel-intercom
API 使用
在 config/services.php
中添加服务配置,并设置环境变量
<?php return [ // ... 'intercom' => [ 'token' => \env('INTERCOM_API_KEY'), 'password' => \env('INTERCOM_PASSWORD'), 'admin_user_id' => \env('INTERCOM_ADMIN_USER_ID'), 'headers' => [ 'Intercom-Version' => '2.3', ], ], // ... ];
然后使用依赖注入 IntercomClient::class
。有关使用信息,请参阅 Intercom PHP。
通知使用
定义类如
final class CommonIntercomNotification extends Notification implements NotificationInterface { use Queueable; /** * @var string */ private string $messageText; /** * @param string $message * * @return void */ public function __construct(string $message) { $this->messageText = $message; } /** * @param mixed $notifiable * * @return array */ public function via($notifiable) { return ['intercom']; } /** * @param mixed $notifiable * * @return IntercomMessage */ public function toIntercom($notifiable): MessageInterface { return new InappMessage($this->messageText); } }
例如,在 User
类中定义返回 ContactInterface
的方法。不要忘记使用 use Notifiable
final class User { use Notifiable; // ... public function routeNotificationForIntercom($notification): ContactInterface { return new GenericMessageContact($this->intercom_contact_id); } }