Check the details at SharpAPI's AI Phone Numbers Detector API page.
- PHP >= 8.1
- Laravel >= 9.0
Follow these steps to install and set up the SharpAPI Laravel Phone Number Detection package.
- Install the package via
composer
:
composer require sharpapi/laravel-content-detect-phones
-
Register at SharpAPI.com to obtain your API key.
-
Set the API key in your
.env
file:
SHARP_API_KEY=your_api_key_here
- [OPTIONAL] Publish the configuration file:
php artisan vendor:publish --tag=sharpapi-content-detect-phones
- AI-Powered Phone Number Detection: Efficiently detect phone numbers in any text content.
- E.164 Format Conversion: Automatically converts detected phone numbers to standardized E.164 format.
- Multiple Number Detection: Identifies all phone numbers present in the provided text.
- International Number Support: Recognizes phone numbers from different countries and formats.
- Robust Polling for Results: Polling-based API response handling with customizable intervals.
- API Availability and Quota Check: Check API availability and current usage quotas with SharpAPI's endpoints.
You can inject the ContentDetectPhonesService
class to access phone number detection functionality. For best results, especially with batch processing, use Laravel's queuing system to optimize job dispatch and result polling.
- Dispatch Job: Send text content to the API using
detectPhones
, which returns a status URL. - Poll for Results: Use
fetchResults($statusUrl)
to poll until the job completes or fails. - Process Result: After completion, retrieve the results from the
SharpApiJob
object returned.
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.
Here is an example of how to use ContentDetectPhonesService
within a Laravel controller:
<?php
namespace App\Http\Controllers;
use GuzzleHttp\Exception\GuzzleException;
use SharpAPI\ContentDetectPhones\ContentDetectPhonesService;
class ContentController extends Controller
{
protected ContentDetectPhonesService $phoneDetectionService;
public function __construct(ContentDetectPhonesService $phoneDetectionService)
{
$this->phoneDetectionService = $phoneDetectionService;
}
/**
* @throws GuzzleException
*/
public function detectPhoneNumbers(string $text)
{
$statusUrl = $this->phoneDetectionService->detectPhones($text);
$result = $this->phoneDetectionService->fetchResults($statusUrl);
return response()->json($result->getResultJson());
}
}
All requests are managed by Guzzle, so it's helpful to be familiar with Guzzle Exceptions.
Example:
use GuzzleHttp\Exception\ClientException;
try {
$statusUrl = $this->phoneDetectionService->detectPhones('Contact us at +1 (800) 555-1234 or 555-6789');
} catch (ClientException $e) {
echo $e->getMessage();
}
You can customize the configuration by setting the following environment variables in your .env
file:
SHARP_API_KEY=your_api_key_here
SHARP_API_JOB_STATUS_POLLING_WAIT=180
SHARP_API_JOB_STATUS_USE_POLLING_INTERVAL=true
SHARP_API_JOB_STATUS_POLLING_INTERVAL=10
SHARP_API_BASE_URL=https://sharpapi.com/api/v1
{
"data": {
"type": "api_job_result",
"id": "d43b36dc-3d1d-4ba7-9a17-36a438d91f09",
"attributes": {
"status": "success",
"type": "content_detect_phones",
"result": [
{
"parsed_number": "+18003947486",
"detected_number": "1800-394-7486"
},
{
"parsed_number": "+6588888888",
"detected_number": "+65 8888 8888"
}
]
}
}
}
For issues or suggestions, please:
Please see CHANGELOG for a detailed list of changes.
- A2Z WEB LTD
- Dawid Makowski
- Enhance your Laravel AI capabilities!
The MIT License (MIT). Please see License File for more information.
Stay updated with news, tutorials, and case studies: