Installation: Add the bundle via Composer:
composer require bbit/airgram-bundle:dev-master
Enable in AppKernel.php:
new BBIT\AirGramBundle\BranchBitAirGramBundle(),
Configuration:
Add to config.yml:
branch_bit_air_gram:
apis:
default:
key: your_airgram_api_key
secret: your_airgram_api_secret
First Use Case: Inject the service in a controller/service:
use BBIT\AirGramBundle\Service\AirGramService;
class MyController extends Controller
{
public function sendNotification(AirGramService $airgram)
{
$airgram->subscribe('user@example.com');
$airgram->send('user@example.com', 'Hello from AirGram!');
}
}
Service Integration:
AirGramService in controllers, commands, or event listeners.UserRegisteredEvent subscriber:
public function onUserRegistered(UserRegisteredEvent $event)
{
$this->airgram->subscribe($event->getUser()->email);
$this->airgram->send($event->getUser()->email, 'Welcome!');
}
API Configuration:
staging, production) in config.yml:
branch_bit_air_gram:
apis:
staging:
key: staging_key
secret: staging_secret
production:
key: prod_key
secret: prod_secret
$this->airgram->setApi('production');
Batch Operations:
foreach ($users as $user) {
$this->airgram->send($user->email, 'Your monthly update');
}
KernelEvents::TERMINATE) to send post-request notifications.try-catch to log failures:
try {
$this->airgram->send($email, $message);
} catch (\Exception $e) {
$this->logger->error('AirGram failed', ['error' => $e->getMessage()]);
}
$mock = $this->createMock(AirGramService::class);
$mock->method('send')->willReturn(true);
$this->container->set('bbit_airgam', $mock);
Deprecated Package:
No Async Support:
Configuration Overrides:
default API key in the bundle’s source (see Services/AirGramService.php).config/services.yml:
services:
bbit_airgam:
class: BBIT\AirGramBundle\Service\AirGramService
arguments: ['@branch_bit_air_gram.api.default']
$response = $this->airgram->getClient()->send($request);
$this->logger->debug('AirGram response', ['status' => $response->getStatusCode(), 'body' => $response->getBody()]);
key/secret in config.yml—invalid credentials return 401 or 403.Custom Payloads:
Extend AirGramService to support custom message templates:
namespace App\Service;
use BBIT\AirGramBundle\Service\AirGramService;
class CustomAirGramService extends AirGramService
{
public function sendTemplate($email, $templateName, array $data)
{
$payload = ['template' => $templateName, 'data' => $data];
return $this->send($email, json_encode($payload));
}
}
Register as a service in config/services.yml:
services:
app.custom_airgram:
class: App\Service\CustomAirGramService
parent: bbit_airgam
Webhook Handling: Add a controller to process AirGram webhooks (if supported):
class AirGramWebhookController extends Controller
{
public function handle(Request $request)
{
$payload = json_decode($request->getContent(), true);
// Process event (e.g., 'message_delivered')
}
}
Route in routing.yml:
airgram_webhook:
path: /airgram/webhook
methods: [POST]
defaults: { _controller: App\Controller\AirGramWebhookController::handle }
Rate Limiting: Implement a decorator to throttle requests:
class ThrottledAirGramService
{
private $decorated;
private $limit;
public function __construct(AirGramService $decorated, int $limit)
{
$this->decorated = $decorated;
$this->limit = $limit;
}
public function send($email, $message)
{
if ($this->exceedsLimit()) {
throw new \RuntimeException('Rate limit exceeded');
}
return $this->decorated->send($email, $message);
}
}
Configure in config/services.yml:
services:
app.throttled_airgram:
class: App\Service\ThrottledAirGramService
arguments: ['@bbit_airgam', 100] # Max 100 requests/hour
How can I help you explore Laravel packages today?