Installation and configuration
To integrate Chat API in a PHP project, add guzzlehttp/guzzle via Composer for HTTP calls. For Laravel, use the built-in HTTP client available from version 7.x.
Configure credentials in the .env file: CHAT_API_KEY=your_api_key.
Sending messages and templates
In Laravel, you can create a dedicated ChatApiService with sendMessage and sendTemplate methods that encapsulate the API call logic. This service can be dependency-injected into controllers or jobs.
Webhook handling in Laravel
For receiving Chat API status webhooks in Laravel, create a POST route and WebhookController. Verify the webhook signature in the header before processing the payload. Use Laravel Jobs for asynchronous webhook processing in the queue.
Best practices for PHP environments
Implement a retry system for failed API calls: save the unsent message in the database with 'pending' status, then a scheduled job retries sending.
For high volumes, use Laravel Queues to queue messages instead of sending synchronously.