Implement multiple phone numbers per workflow feature

Database Changes:
- Added twp_workflow_phones junction table for many-to-many relationship
- Updated activator to create and manage new table
- Maintained backward compatibility with existing phone_number field

Workflow Management:
- Added set_workflow_phone_numbers() and get_workflow_phone_numbers() methods
- Updated get_workflow_by_phone_number() to check both old and new structures
- Enhanced save/update handlers to support phone_numbers array
- Added AJAX endpoint for retrieving workflow phone numbers

User Interface:
- Replaced single phone number select with dynamic multi-select interface
- Added "Add Number" and "Remove" buttons for managing multiple numbers
- Updated workflow listing to display all assigned phone numbers
- Enhanced JavaScript for phone number management and validation

The webhook routing already supports multiple numbers since get_workflow_by_phone_number()
was updated to check both structures. This feature allows users to assign multiple
Twilio phone numbers to trigger the same workflow.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-08-13 10:35:21 -07:00
parent 30b0cd355f
commit aa58b45501
5 changed files with 254 additions and 19 deletions

View File

@@ -37,6 +37,7 @@ class TWP_Activator {
'twp_call_queues',
'twp_queued_calls',
'twp_workflows',
'twp_workflow_phones',
'twp_call_log',
'twp_sms_log',
'twp_voicemails',
@@ -137,7 +138,7 @@ class TWP_Activator {
KEY status (status)
) $charset_collate;";
// Workflows table
// Workflows table (keeping phone_number for backward compatibility, will be deprecated)
$table_workflows = $wpdb->prefix . 'twp_workflows';
$sql_workflows = "CREATE TABLE $table_workflows (
id int(11) NOT NULL AUTO_INCREMENT,
@@ -151,6 +152,19 @@ class TWP_Activator {
KEY phone_number (phone_number)
) $charset_collate;";
// Workflow phone numbers junction table
$table_workflow_phones = $wpdb->prefix . 'twp_workflow_phones';
$sql_workflow_phones = "CREATE TABLE $table_workflow_phones (
id int(11) NOT NULL AUTO_INCREMENT,
workflow_id int(11) NOT NULL,
phone_number varchar(20) NOT NULL,
created_at datetime DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY workflow_phone (workflow_id, phone_number),
KEY workflow_id (workflow_id),
KEY phone_number (phone_number)
) $charset_collate;";
// Call log table
$table_call_log = $wpdb->prefix . 'twp_call_log';
$sql_call_log = "CREATE TABLE $table_call_log (
@@ -274,6 +288,7 @@ class TWP_Activator {
dbDelta($sql_queues);
dbDelta($sql_queued_calls);
dbDelta($sql_workflows);
dbDelta($sql_workflow_phones);
dbDelta($sql_call_log);
dbDelta($sql_sms_log);
dbDelta($sql_voicemails);