Skip to content

Commit 8ecc189

Browse files
committed
first commit
0 parents  commit 8ecc189

File tree

1 file changed

+200
-0
lines changed

1 file changed

+200
-0
lines changed

README.md

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
![SharpAPI GitHub cover](https://sharpapi.com/sharpapi-github-laravel-bg.jpg "SharpAPI Laravel Client")
2+
3+
# AI Email Detection for Laravel
4+
5+
## 🚀 Leverage AI API to detect and extract email addresses from text content.
6+
7+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/sharpapi/laravel-content-detect-emails.svg?style=flat-square)](https://packagist.org/packages/sharpapi/laravel-content-detect-emails)
8+
[![Total Downloads](https://img.shields.io/packagist/dt/sharpapi/laravel-content-detect-emails.svg?style=flat-square)](https://packagist.org/packages/sharpapi/laravel-content-detect-emails)
9+
10+
Check the details at SharpAPI's [Content API](https://sharpapi.com/en/catalog/ai/content) page.
11+
12+
---
13+
14+
## Requirements
15+
16+
- PHP >= 8.1
17+
- Laravel >= 9.0
18+
19+
---
20+
21+
## Installation
22+
23+
Follow these steps to install and set up the SharpAPI Laravel Email Detection package.
24+
25+
1. Install the package via `composer`:
26+
27+
```bash
28+
composer require sharpapi/laravel-content-detect-emails
29+
```
30+
31+
2. Register at [SharpAPI.com](https://sharpapi.com/) to obtain your API key.
32+
33+
3. Set the API key in your `.env` file:
34+
35+
```bash
36+
SHARP_API_KEY=your_api_key_here
37+
```
38+
39+
4. **[OPTIONAL]** Publish the configuration file:
40+
41+
```bash
42+
php artisan vendor:publish --tag=sharpapi-content-detect-emails
43+
```
44+
45+
---
46+
## Key Features
47+
48+
- **AI-Powered Email Detection**: Efficiently detect email addresses in any text content.
49+
- **Multiple Email Detection**: Identifies all email addresses present in the provided text.
50+
- **Format Validation**: Ensures detected emails are properly formatted.
51+
- **Obfuscated Email Detection**: Can detect emails that are partially obfuscated or formatted in non-standard ways.
52+
- **Robust Polling for Results**: Polling-based API response handling with customizable intervals.
53+
- **API Availability and Quota Check**: Check API availability and current usage quotas with SharpAPI's endpoints.
54+
55+
---
56+
57+
## Usage
58+
59+
You can inject the `ContentDetectEmailsService` class to access email detection functionality. For best results, especially with batch processing, use Laravel's queuing system to optimize job dispatch and result polling.
60+
61+
### Basic Workflow
62+
63+
1. **Dispatch Job**: Send text content to the API using `detectEmails`, which returns a status URL.
64+
2. **Poll for Results**: Use `fetchResults($statusUrl)` to poll until the job completes or fails.
65+
3. **Process Result**: After completion, retrieve the results from the `SharpApiJob` object returned.
66+
67+
> **Note**: Each job typically takes a few seconds to complete. Once completed successfully, the status will update to `success`, and you can process the results as JSON, array, or object format.
68+
69+
---
70+
71+
### Controller Example
72+
73+
Here is an example of how to use `ContentDetectEmailsService` within a Laravel controller:
74+
75+
```php
76+
<?php
77+
78+
namespace App\Http\Controllers;
79+
80+
use GuzzleHttp\Exception\GuzzleException;
81+
use SharpAPI\ContentDetectEmails\ContentDetectEmailsService;
82+
83+
class ContentController extends Controller
84+
{
85+
protected ContentDetectEmailsService $emailDetectionService;
86+
87+
public function __construct(ContentDetectEmailsService $emailDetectionService)
88+
{
89+
$this->emailDetectionService = $emailDetectionService;
90+
}
91+
92+
/**
93+
* @throws GuzzleException
94+
*/
95+
public function detectEmailAddresses(string $text)
96+
{
97+
$statusUrl = $this->emailDetectionService->detectEmails($text);
98+
99+
$result = $this->emailDetectionService->fetchResults($statusUrl);
100+
101+
return response()->json($result->getResultJson());
102+
}
103+
}
104+
```
105+
106+
### Handling Guzzle Exceptions
107+
108+
All requests are managed by Guzzle, so it's helpful to be familiar with [Guzzle Exceptions](https://docs.guzzlephp.org/en/stable/quickstart.html#exceptions).
109+
110+
Example:
111+
112+
```php
113+
use GuzzleHttp\Exception\ClientException;
114+
115+
try {
116+
$statusUrl = $this->emailDetectionService->detectEmails('Contact us at [email protected] or [email protected]');
117+
} catch (ClientException $e) {
118+
echo $e->getMessage();
119+
}
120+
```
121+
122+
---
123+
124+
## Optional Configuration
125+
126+
You can customize the configuration by setting the following environment variables in your `.env` file:
127+
128+
```bash
129+
SHARP_API_KEY=your_api_key_here
130+
SHARP_API_JOB_STATUS_POLLING_WAIT=180
131+
SHARP_API_JOB_STATUS_USE_POLLING_INTERVAL=true
132+
SHARP_API_JOB_STATUS_POLLING_INTERVAL=10
133+
SHARP_API_BASE_URL=https://sharpapi.com/api/v1
134+
```
135+
136+
---
137+
138+
## Email Detection Data Format Example
139+
140+
```json
141+
{
142+
"data": {
143+
"type": "api_job_result",
144+
"id": "5a113c4d-38e9-43e5-80f4-ec3fdea3420e",
145+
"attributes": {
146+
"status": "success",
147+
"type": "content_detect_emails",
148+
"result": [
149+
{
150+
"email": "[email protected]"
151+
},
152+
{
153+
"email": "[email protected]"
154+
}
155+
]
156+
}
157+
}
158+
}
159+
```
160+
161+
---
162+
163+
## Support & Feedback
164+
165+
For issues or suggestions, please:
166+
167+
- [Open an issue on GitHub](https://github.com/sharpapi/laravel-content-detect-emails/issues)
168+
- Join our [Telegram community](https://t.me/sharpapi_community)
169+
170+
---
171+
172+
## Changelog
173+
174+
Please see [CHANGELOG](CHANGELOG.md) for a detailed list of changes.
175+
176+
---
177+
178+
## Credits
179+
180+
- [A2Z WEB LTD](https://github.com/a2zwebltd)
181+
- [Dawid Makowski](https://github.com/makowskid)
182+
- Enhance your [Laravel AI](https://sharpapi.com/) capabilities!
183+
184+
---
185+
186+
## License
187+
188+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
189+
190+
---
191+
192+
## Follow Us
193+
194+
Stay updated with news, tutorials, and case studies:
195+
196+
- [SharpAPI on X (Twitter)](https://x.com/SharpAPI)
197+
- [SharpAPI on YouTube](https://www.youtube.com/@SharpAPI)
198+
- [SharpAPI on Vimeo](https://vimeo.com/SharpAPI)
199+
- [SharpAPI on LinkedIn](https://www.linkedin.com/products/a2z-web-ltd-sharpapicom-automate-with-aipowered-api/)
200+
- [SharpAPI on Facebook](https://www.facebook.com/profile.php?id=61554115896974)

0 commit comments

Comments
 (0)