Files
michaelschiemer/tests/debug/test-whatsapp-notification.php
Michael Schiemer 3b623e7afb feat(Deployment): Integrate Ansible deployment via PHP deployment pipeline
- Create AnsibleDeployStage using framework's Process module for secure command execution
- Integrate AnsibleDeployStage into DeploymentPipelineCommands for production deployments
- Add force_deploy flag support in Ansible playbook to override stale locks
- Use PHP deployment module as orchestrator (php console.php deploy:production)
- Fix ErrorAggregationInitializer to use Environment class instead of $_ENV superglobal

Architecture:
- BuildStage → AnsibleDeployStage → HealthCheckStage for production
- Process module provides timeout, error handling, and output capture
- Ansible playbook supports rollback via rollback-git-based.yml
- Zero-downtime deployments with health checks
2025-10-26 14:08:07 +01:00

91 lines
3.5 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
use App\Framework\Core\ValueObjects\PhoneNumber;
use App\Framework\HttpClient\CurlHttpClient;
use App\Framework\Notification\Channels\WhatsApp\WhatsAppClient;
use App\Framework\Notification\Channels\WhatsApp\WhatsAppConfig;
use App\Framework\Notification\Channels\WhatsApp\ValueObjects\WhatsAppTemplateId;
echo "🔷 WhatsApp Notification Test\n";
echo str_repeat('=', 50) . "\n\n";
try {
// 1. Create WhatsApp configuration
echo "1⃣ Creating WhatsApp configuration...\n";
$config = WhatsAppConfig::createDefault();
echo " ✅ Config created\n";
echo " 📞 Phone Number ID: {$config->phoneNumberId}\n";
echo " 🔗 API URL: {$config->getApiUrl()}\n\n";
// 2. Create HTTP client and WhatsApp client
echo "2⃣ Creating WhatsApp client...\n";
$httpClient = new CurlHttpClient();
$whatsappClient = new WhatsAppClient($httpClient, $config);
echo " ✅ Client created\n\n";
// 3. Test phone number
$testPhoneNumber = PhoneNumber::fromString('+4917941122213');
echo "3⃣ Test recipient: {$testPhoneNumber->toDisplayFormat()}\n\n";
// 4. Send text message
echo "4⃣ Sending text message...\n";
try {
$response = $whatsappClient->sendTextMessage(
to: $testPhoneNumber,
message: "🎉 Test message from Custom PHP Framework!\n\nThis is a test notification via WhatsApp Business API."
);
echo " ✅ Message sent successfully!\n";
echo " 📨 Message ID: {$response->messageId->toString()}\n\n";
} catch (\Throwable $e) {
echo " ❌ Text message failed: {$e->getMessage()}\n\n";
}
// 5. Send template message (hello_world template)
echo "5⃣ Sending template message...\n";
try {
$templateResponse = $whatsappClient->sendTemplateMessage(
to: $testPhoneNumber,
templateId: WhatsAppTemplateId::fromString('hello_world'),
languageCode: 'en_US'
);
echo " ✅ Template message sent successfully!\n";
echo " 📨 Message ID: {$templateResponse->messageId->toString()}\n\n";
} catch (\Throwable $e) {
echo " ❌ Template message failed: {$e->getMessage()}\n\n";
}
// 6. Test with parameters (if you have a template with parameters)
echo "6⃣ Sending template with parameters...\n";
try {
$paramResponse = $whatsappClient->sendTemplateMessage(
to: $testPhoneNumber,
templateId: WhatsAppTemplateId::fromString('sample_template'), // Replace with your template
languageCode: 'en',
parameters: ['John Doe', '2024-12-20']
);
echo " ✅ Parametrized template sent!\n";
echo " 📨 Message ID: {$paramResponse->messageId->toString()}\n\n";
} catch (\Throwable $e) {
echo " Parametrized template skipped: {$e->getMessage()}\n\n";
}
echo "✅ WhatsApp notification test completed!\n\n";
echo "📝 Notes:\n";
echo " - Replace test phone number with your WhatsApp number\n";
echo " - Phone number must be in E.164 format (+country code + number)\n";
echo " - Make sure the number is registered with your WhatsApp Business account\n";
echo " - Template names must be approved in your WhatsApp Business account\n";
} catch (\Throwable $e) {
echo "\n❌ Test failed: {$e->getMessage()}\n";
echo "Stack trace:\n{$e->getTraceAsString()}\n";
exit(1);
}