Fix FCM token registration and add queue reminder alerts
- Fix silent insert failure in FCM token registration (missing NOT NULL refresh_token column) so WebView app tokens are actually stored - Add 1-minute queue reminder cron that re-sends FCM alerts for calls still waiting, with transient-based throttle to prevent duplicates - Send FCM cancel on queue dequeue (answered/hangup/timeout), not just on final call status webhook - Clean up new cron hook on plugin deactivation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1276,10 +1276,24 @@ class TWP_Webhooks {
|
||||
|
||||
if ($updated) {
|
||||
error_log('TWP Queue Action: Updated call status to ' . $status);
|
||||
|
||||
// Cancel FCM queue alerts when call leaves the queue for any reason
|
||||
if (in_array($status, array('answered', 'hangup', 'transferred', 'timeout', 'completed'))) {
|
||||
$queued_call = $wpdb->get_row($wpdb->prepare(
|
||||
"SELECT queue_id FROM $table_name WHERE call_sid = %s",
|
||||
$call_sid
|
||||
));
|
||||
if ($queued_call) {
|
||||
require_once plugin_dir_path(__FILE__) . 'class-twp-fcm.php';
|
||||
$fcm = new TWP_FCM();
|
||||
$fcm->cancel_queue_alert_for_queue($queued_call->queue_id, $call_sid);
|
||||
error_log('TWP Queue Action: Sent FCM cancel for call ' . $call_sid);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
error_log('TWP Queue Action: No call found to update with SID ' . $call_sid);
|
||||
}
|
||||
|
||||
|
||||
// Return empty response - this is just for tracking
|
||||
return $this->send_twiml_response('<Response></Response>');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user