fix(turnero): route incoming messages by phone_number_id and fix WhatsAppService canal
- WhatsAppService($canal): when 'turnero', swaps phoneNumberId to whatsapp_phone_number_id_turnero so outgoing messages actually go from the turnero number (not the main bot) - webhook.php: reads metadata.phone_number_id from the payload and compares it to whatsapp_phone_number_id_turnero; if it matches, saves canal='turnero' and skips bot processing - Previously all incoming messages had canal=NULL/bot so Chat Turnero never saw them, and all outgoing messages from Chat Turnero were sent via the wrong (main bot) number Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
00aee615c5
commit
5acd46df5a
@@ -22,14 +22,23 @@ class WhatsAppService
|
||||
private $db;
|
||||
private $rateLimitMonitor;
|
||||
|
||||
public function __construct()
|
||||
public function __construct($canal = null)
|
||||
{
|
||||
// Obtener configuración desde base de datos
|
||||
$config = getWhatsAppConfigFromDB();
|
||||
|
||||
$this->token = $config['token']; // Usar token de BD
|
||||
$this->phoneNumberId = $config['phone_number_id']; // Usar phone_number_id de BD
|
||||
$this->apiUrl = $config['api_url'] ?: 'https://graph.facebook.com/v22.0/'; // Usar api_url de BD
|
||||
|
||||
$this->token = $config['token'];
|
||||
$this->phoneNumberId = $config['phone_number_id'];
|
||||
$this->apiUrl = $config['api_url'] ?: 'https://graph.facebook.com/v22.0/';
|
||||
|
||||
// Si se especifica canal 'turnero', usar el phone ID del número turnero
|
||||
if ($canal === 'turnero') {
|
||||
$turneroPhoneId = getConfigFromDB('whatsapp_phone_number_id_turnero', '');
|
||||
if ($turneroPhoneId) {
|
||||
$this->phoneNumberId = $turneroPhoneId;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db = Database::getInstance();
|
||||
|
||||
// Inicializar monitor de rate limit
|
||||
|
||||
Reference in New Issue
Block a user