mediumart / intercom
Intercom API [可宏定义] 客户端适配器,适用于laravel
Requires
- illuminate/support: ~5.0|6.*|7.*
- intercom/intercom-php: ^3.1
Requires (Dev)
- mockery/mockery: 0.9.*
- orchestra/testbench: ^3.4
- phpunit/phpunit: ~5.7
- dev-master
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- 0.0.3
- 0.0.2
- 0.0.1
- dev-dependabot/composer/guzzlehttp/guzzle-6.5.8
- dev-dependabot/composer/erusev/parsedown-1.7.4
- dev-dependabot/composer/guzzlehttp/psr7-1.8.5
- dev-dependabot/composer/symfony/http-kernel-3.4.49
- dev-dependabot/composer/league/flysystem-1.1.4
This package is auto-updated.
Last update: 2024-09-21 22:53:52 UTC
README
Mediumart Intercom 客户端是可宏定义的!
安装
要安装,首先使用composer要求该软件包
$ composer require mediumart/intercom
然后,将以下内容添加到您的 config/app.php
文件中的 'providers'
数组内
Mediumart\Intercom\IntercomServiceProvider::class
并在 'aliases'
数组内添加外观引用
'Intercom' => Mediumart\Intercom\Intercom::class
配置
您需要使用您的 intercom.io 帐户创建一个具有相关 access_token
的 app
。您可以在这里找到如何操作的信息。
一旦您获得了访问令牌,打开您的laravel项目的 config/services.php
文件,并添加一个类似于以下内容的 intercom
服务键:
'intercom' => [
'access_token' => '<your_access_token>'
]
该软件包将自动提取令牌以验证对您自己的Intercom数据的任何API请求。
使用方法
您可以通过多种方式解析intercom Client
use Mediumart\Intercom\Client; /** * Manually resolving from the container * */ $intercom = app('intercom'); // or $intercom = app(Client::class); /** * using type hinting and laravel's automatic resolution * */ public function index(Client $intercom) { /.../ } /** * Simply leverage the facade * */ $intercomUsers = Intercom::users();
使用 instance
或 facade
,任何资源类型都将作为 Client
上的方法镜像,可用于获取相应的资源对象
// facade $leads = Intercom::leads(); // instance $intercom = app('intercom'); $conversations = $intercom->conversations();
使用 instance
方法,您还可以将资源实例解析为 Client
的属性
$conversations = $intercom->conversations;
以下是所有Intercom资源类型的列表
users
events
companies
messages
conversations
leads
visitors
admins
tags
segments
counts
bulk
notes
您可以在他们的官方文档页面上找到相关信息,以及每个资源的API使用方法这里。
此外,您还可以在解析 Client
之后以流畅的方式设置令牌,使用 setToken
方法
$intercom->setToken($token)->users->getUser($id);
定义宏
要创建宏函数,您可以在 facade
或 instance
上使用 macro
方法,此方法接受一个 name
作为其第一个参数,并接受一个 callable
作为其第二个参数。
// facade Intercom::macro('usersEmails', function () { return // your logic here ... }); // instance $intercom->macro('usersEmails', function () use ($intercom) { return // your logic here ... });
现在,您可以像调用常规方法一样调用您的 macro
// facade $userEmails = Intercom::usersEmails(); // instance $userEmails = $intercom->usersEmails();
许可
Mediumart Intercom 是一个开源软件,许可协议为 MIT 许可。