Skip to content

Commit 761d60f

Browse files
committed
Improve documentation
1 parent fe546b0 commit 761d60f

File tree

3 files changed

+118
-22
lines changed

3 files changed

+118
-22
lines changed

README.md

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,65 @@ composer require ziming/laravel-crisp
2222
You can publish the config file with:
2323

2424
```bash
25-
php artisan vendor:publish --tag="laravel-crisp-config"
25+
php artisan vendor:publish --tag="crisp-config"
2626
```
2727

2828
This is the contents of the published config file:
2929

3030
```php
3131
return [
3232
'website_id' => env('CRISP_WEBSITE_ID'),
33+
'tier' => env('CRISP_TIER', 'plugin'),
3334
'access_key_id' => env('CRISP_ACCESS_KEY_ID'),
3435
'secret_access_key' => env('CRISP_SECRET_ACCESS_KEY'),
3536
];
3637
```
3738

3839
## Usage
3940

41+
So what are the differences between the Crisp's official PHP SDK and this package?
42+
43+
The 1st main difference is that you don't have to set the tier & api credentials every time after instantiating
44+
45+
You also do not have to pass in the `website_id` every time.
46+
47+
I hope through the example below, you can see how much more convenient this brings for those of 1 who only have a single
48+
Crisp workspace.
49+
50+
4051
```php
41-
$crisp = new Ziming\LaravelCrisp();
52+
// Official PHP Crisp SDK
53+
use Crisp\CrispClient;
54+
$officialCrisp = new CrispClient();
55+
$officialCrisp->setTier('plugin');
56+
$officialCrisp->authenticate(config('crisp.access_key_id'), config('crisp.secret_access_key'));
57+
$officialCrisp->websitePeople->findByEmail(config('crisp.website_id'), '[email protected]');
58+
59+
// This package
60+
$laravelCrisp = new Ziming\LaravelCrisp();
61+
$laravelCrisp->websitePeople->findByEmail('[email protected]');
62+
63+
// If you prefer the laravel facade approach you can just do this
64+
\Ziming\LaravelCrisp\Facades\LaravelCrisp::websitePeople()->findByEmail('[email protected]');
65+
66+
// If for some reason you want to use a different website_id, the official Crisp client is always available too
67+
$laravelCrisp->officialClient->websitePeople->findByEmail(config('crisp.website_id'), '[email protected]');
68+
```
69+
70+
The second main difference are extra methods that I think are useful but are not in Crisp official SDK when I 1st
71+
added them. For now it is just these 3.
72+
73+
```php
74+
// Gives you the Crisp Profile Link in Crisp
75+
\Ziming\LaravelCrisp\Resources\WebsitePeople::getProfileLink('people-id');
76+
77+
// Get the first people id that matches the search text if 1 or more results are returned
78+
$laravelCrisp = new Ziming\LaravelCrisp();
79+
$laravelCrisp->websitePeople->getFirstPeopleIdBySearchText('[email protected]');
4280

43-
// Notice you don't have to pass in the website_id every time.
44-
$crisp->websitePeople->findByEmail('[email protected]');
81+
// Gives you the conversation link in Crisp
82+
\Ziming\LaravelCrisp\Resources\WebsiteConversations::getConversationLink('session-id');
4583

46-
// Alternatively you can use the crisp php api sdk but that would need you to pass in the website_id every time
47-
$crisp->client->websitePeople->findByEmail('crisp-website-id', '[email protected]');
4884
```
4985

5086
## Testing

src/LaravelCrisp.php

Lines changed: 75 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
final class LaravelCrisp
2121
{
22-
public CrispClient $client;
22+
public CrispClient $officialClient;
2323

2424
public WebsitePeople $websitePeople;
2525

@@ -45,24 +45,84 @@ final class LaravelCrisp
4545

4646
public function __construct()
4747
{
48-
$this->client = new CrispClient;
49-
$this->client->setTier(config('crisp.tier'));
50-
$this->client->authenticate(
48+
$this->officialClient = new CrispClient;
49+
$this->officialClient->setTier(config('crisp.tier'));
50+
$this->officialClient->authenticate(
5151
config('crisp.access_key_id'),
5252
config('crisp.secret_access_key')
5353
);
5454

5555
// Initialize all resource classes
56-
$this->websitePeople = new WebsitePeople($this->client);
57-
$this->websiteConversations = new WebsiteConversations($this->client);
58-
$this->websiteSettings = new WebsiteSettings($this->client);
59-
$this->websiteOperators = new WebsiteOperators($this->client);
60-
$this->websiteVisitors = new WebsiteVisitors($this->client);
61-
$this->websiteAvailability = new WebsiteAvailability($this->client);
62-
$this->websiteVerify = new WebsiteVerify($this->client);
63-
$this->userProfile = new UserProfile($this->client);
64-
$this->pluginSubscriptions = new PluginSubscriptions($this->client);
65-
$this->buckets = new Buckets($this->client);
66-
$this->website = new Website($this->client);
56+
$this->websitePeople = new WebsitePeople($this->officialClient);
57+
$this->websiteConversations = new WebsiteConversations($this->officialClient);
58+
$this->websiteSettings = new WebsiteSettings($this->officialClient);
59+
$this->websiteOperators = new WebsiteOperators($this->officialClient);
60+
$this->websiteVisitors = new WebsiteVisitors($this->officialClient);
61+
$this->websiteAvailability = new WebsiteAvailability($this->officialClient);
62+
$this->websiteVerify = new WebsiteVerify($this->officialClient);
63+
$this->userProfile = new UserProfile($this->officialClient);
64+
$this->pluginSubscriptions = new PluginSubscriptions($this->officialClient);
65+
$this->buckets = new Buckets($this->officialClient);
66+
$this->website = new Website($this->officialClient);
67+
}
68+
69+
public function websitePeople(): WebsitePeople
70+
{
71+
return $this->websitePeople;
72+
}
73+
74+
public function websiteConversations(): WebsiteConversations
75+
{
76+
return $this->websiteConversations;
77+
}
78+
79+
public function websiteSettings(): WebsiteSettings
80+
{
81+
return $this->websiteSettings;
82+
}
83+
84+
public function websiteOperators(): WebsiteOperators
85+
{
86+
return $this->websiteOperators;
87+
}
88+
89+
public function websiteVisitors(): WebsiteVisitors
90+
{
91+
return $this->websiteVisitors;
92+
}
93+
94+
public function websiteAvailability(): WebsiteAvailability
95+
{
96+
return $this->websiteAvailability;
97+
}
98+
99+
public function websiteVerify(): WebsiteVerify
100+
{
101+
return $this->websiteVerify;
102+
}
103+
104+
public function userProfile(): UserProfile
105+
{
106+
return $this->userProfile;
107+
}
108+
109+
public function pluginSubscriptions(): PluginSubscriptions
110+
{
111+
return $this->pluginSubscriptions;
112+
}
113+
114+
public function buckets(): Buckets
115+
{
116+
return $this->buckets;
117+
}
118+
119+
public function website(): Website
120+
{
121+
return $this->website;
122+
}
123+
124+
public function officialClient(): CrispClient
125+
{
126+
return $this->officialClient;
67127
}
68128
}

src/Resources/WebsitePeople.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public function updatePeopleSubscriptionStatus(string $peopleId, array $data): a
239239
/**
240240
* Bonus Method
241241
* Get the first people ID by search text.
242-
*
242+
* I may rename this method in the future as it does not feel right to me.
243243
* @throws CrispException
244244
* @throws ClientExceptionInterface
245245
*/

0 commit comments

Comments
 (0)