Compare commits
3 Commits
2026.03.06
...
2026.03.06
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8cc6fa8c3c | ||
|
|
d41b6aa535 | ||
|
|
4da794ed0c |
97
CLAUDE.md
97
CLAUDE.md
@@ -6,8 +6,26 @@
|
||||
- **URL**: `https://phone.cloud-hosting.io/`
|
||||
- **Deployment**: rsync to Docker (remote server only, not local)
|
||||
- **SDK**: Twilio PHP SDK v8.7.0
|
||||
- **PHP**: 8.0+ required
|
||||
- **Optional**: AWS SDK (`aws/aws-sdk-php`) for SNS SMS provider
|
||||
- **External SDK**: `wp-content/twilio-sdk/` (survives plugin updates)
|
||||
|
||||
## Commands
|
||||
- **Install SDK (recommended)**: `./install-twilio-sdk-external.sh` (installs to `wp-content/twilio-sdk/`)
|
||||
- **Install SDK (internal)**: `./install-twilio-sdk.sh` (installs to `vendor/`, lost on plugin update)
|
||||
- **Test SDK**: `php test-sdk.php`
|
||||
- **Composer install SDK**: `composer install-sdk`
|
||||
- **Deploy**: rsync to Docker (remote server, see production path above)
|
||||
- **CI/CD**: Gitea workflows in `.gitea/workflows/` — `release.yml`, `update-version.yml`
|
||||
|
||||
## Directory Structure
|
||||
- `twilio-wp-plugin.php` — Main plugin file, constants, SDK loading
|
||||
- `includes/` — All backend classes (28 class files)
|
||||
- `admin/` — Admin UI class (`TWP_Admin`), mobile app settings page
|
||||
- `assets/js/` — Browser phone JS, service worker
|
||||
- `assets/images/`, `assets/sounds/` — Static assets
|
||||
- `.gitea/workflows/` — CI/CD (release, version update)
|
||||
|
||||
## Phone Variable Names
|
||||
**Use**: `incoming_number`, `agent_number`, `customer_number`, `workflow_number`, `queue_number`, `default_number`
|
||||
**Don't use**: `from_number`, `to_number`, `phone_number`, `$agent_phone`
|
||||
@@ -18,11 +36,20 @@
|
||||
- **TWP_Admin**: Has `find_customer_call_leg()` - CRITICAL for call control
|
||||
- **TWP_TTS_Helper**: ElevenLabs/Alice fallback, 30-day cache
|
||||
- **TWP_User_Queue_Manager**: Auto-creates queues/extensions (100-9999)
|
||||
- **TWP_Webhooks**: 26 endpoints at `twilio-webhook/v1`
|
||||
- **TWP_Activator**: Creates 15 DB tables, run `ensure_tables_exist()` if missing
|
||||
- **TWP_Webhooks**: 35 endpoints at `twilio-webhook/v1`
|
||||
- **TWP_Activator**: Creates 16 DB tables, run `ensure_tables_exist()` if missing
|
||||
- **TWP_Core**: Main plugin orchestrator, hooks all classes together
|
||||
- **TWP_SMS_Manager**: SMS abstraction with provider interface
|
||||
- **TWP_SMS_Provider_Twilio** / **TWP_SMS_Provider_SNS**: SMS providers (Twilio default, AWS SNS optional)
|
||||
- **TWP_Mobile_API**: REST API for mobile app
|
||||
- **TWP_Mobile_Auth** / **TWP_Mobile_SSE** / **TWP_FCM**: Mobile auth, server-sent events, push notifications
|
||||
- **TWP_Call_Queue**: Queue operations and management
|
||||
- **TWP_Callback_Manager**: Callback request handling
|
||||
- **TWP_Workflow**: Workflow step execution engine
|
||||
- **TWP_Auto_Updater**: Plugin auto-update from Gitea releases
|
||||
|
||||
## Database
|
||||
15 tables with `twp_` prefix. Key notes:
|
||||
16 tables with `twp_` prefix. Key notes:
|
||||
- `twp_call_queues`: User queues (general/personal/hold)
|
||||
- `twp_agent_status`: Has `auto_busy_at` for 1-min auto-revert
|
||||
- `twp_queued_calls`: Uses `enqueued_at` not `joined_at`
|
||||
@@ -41,32 +68,6 @@ $api->update_call($customer_call_sid, ['twiml' => $twiml_xml]);
|
||||
- Queue: Pass `waitUrl` as option in `enqueue()`
|
||||
- TwiML: Use SDK classes, not raw XML
|
||||
|
||||
## Recent Changes (v2.3.0)
|
||||
- Browser phone moved to admin-only
|
||||
- Call control uses `find_customer_call_leg()` to prevent disconnections
|
||||
- Auto-creates user queues/extensions when needed
|
||||
- Firefox support added
|
||||
- 1-min agent status auto-revert
|
||||
|
||||
## SDK Installation
|
||||
- **External SDK (Recommended)**: Use `install-twilio-sdk-external.sh` to install SDK to `wp-content/twilio-sdk/`
|
||||
- Survives WordPress plugin updates
|
||||
- SDK location defined by `TWP_EXTERNAL_SDK_DIR` constant
|
||||
- Loading priority: External first, then internal `vendor/` fallback
|
||||
- **Internal SDK (Alternative)**: Use `install-twilio-sdk.sh` to install to `vendor/`
|
||||
- Will be deleted when WordPress updates the plugin
|
||||
- Requires reinstallation after each plugin update
|
||||
- **SDK Loading**: Plugin checks external location first via autoloader, falls back to internal
|
||||
- **Post-Update Detection**: Hook on `upgrader_process_complete` checks SDK status and shows warning
|
||||
|
||||
## Browser Phone Configuration
|
||||
- **Edge Location Setting**: Configurable via Settings → Twilio Edge Location
|
||||
- Default: `roaming` (auto-select closest edge)
|
||||
- Options: ashburn, umatilla, dublin, frankfurt, singapore, sydney, tokyo, sao-paulo
|
||||
- Stored in: `twp_twilio_edge` option
|
||||
- Used by: Browser phone JavaScript for WebRTC connection
|
||||
- Critical: Wrong edge causes immediate call failures (e.g., US calls with Sydney edge)
|
||||
|
||||
## Development Notes
|
||||
- **API**: E.164 format (+1XXXXXXXXXX)
|
||||
- **Database**: Use `$wpdb`, prepared statements
|
||||
@@ -79,30 +80,24 @@ $api->update_call($customer_call_sid, ['twiml' => $twiml_xml]);
|
||||
- User-specific queues with extensions
|
||||
- Browser phone at `admin.php?page=twilio-wp-browser-phone`
|
||||
- ElevenLabs TTS with Alice fallback
|
||||
- 68 AJAX actions, 26 REST endpoints
|
||||
- 77 AJAX actions, 35 REST endpoints
|
||||
- Browser phone moved to admin-only (v2.3.0)
|
||||
- Firefox, Chrome, Safari, Edge support
|
||||
- 1-min agent status auto-revert
|
||||
|
||||
## Recent Technical Changes (v2.8.9)
|
||||
## SDK Loading
|
||||
- **External SDK (Recommended)**: `wp-content/twilio-sdk/` — survives plugin updates
|
||||
- **Internal SDK**: `vendor/` — deleted on plugin update, needs reinstall
|
||||
- Loading priority: External first (`TWP_EXTERNAL_SDK_DIR`), then internal fallback
|
||||
- Post-update hook (`upgrader_process_complete`) warns if SDK missing
|
||||
|
||||
### SDK Persistence Between Plugin Updates
|
||||
- **Problem**: WordPress plugin updates delete entire plugin folder including `vendor/` SDK
|
||||
- **Solution**: External SDK installation at `wp-content/twilio-sdk/` survives updates
|
||||
- **Implementation**:
|
||||
- New constant: `TWP_EXTERNAL_SDK_DIR` points to `wp-content/twilio-sdk/`
|
||||
- Loading priority in `twp_check_sdk_installation()`: External first, internal fallback
|
||||
- Classes updated: `TWP_Twilio_API`, `TWP_Webhooks` constructors check external location first
|
||||
- New script: `install-twilio-sdk-external.sh` automates external installation
|
||||
- Post-update hook: `twp_check_sdk_after_update()` detects missing SDK after updates
|
||||
- Admin notices: `twp_sdk_missing_notice()` shows both installation options
|
||||
- Warning system: `twp_show_sdk_update_warning()` via transient after plugin updates
|
||||
## Browser Phone Configuration
|
||||
- **Edge Location**: `twp_twilio_edge` option, default `roaming`
|
||||
- Options: roaming, ashburn, umatilla, dublin, frankfurt, singapore, sydney, tokyo, sao-paulo
|
||||
- Wrong edge causes immediate call failures (e.g., US calls with Sydney edge)
|
||||
|
||||
### US Calls Failing Fix (Browser Phone)
|
||||
- **Problem**: Browser phone had hardcoded `edge: 'sydney'`, causing US calls to fail with immediate HANGUP
|
||||
- **Solution**: Configurable edge location via WordPress settings
|
||||
- **Implementation**:
|
||||
- New setting: `twp_twilio_edge` with default value `roaming`
|
||||
- Settings UI: Dropdown in admin settings with 8 edge options
|
||||
- Browser phone JS: Uses `get_option('twp_twilio_edge', 'roaming')` instead of hardcoded value
|
||||
- Edge options: roaming, ashburn, umatilla, dublin, frankfurt, singapore, sydney, tokyo, sao-paulo
|
||||
## Changelog
|
||||
See `README.md` for detailed version history. Current version: v2.8.9.
|
||||
|
||||
---
|
||||
*Updated: Jan 2026*
|
||||
*Updated: Mar 2026*
|
||||
@@ -52,9 +52,6 @@ if (isset($_POST['twp_save_mobile_settings']) && check_admin_referer('twp_mobile
|
||||
update_option('twp_auto_update_enabled', isset($_POST['twp_auto_update_enabled']) ? '1' : '0');
|
||||
update_option('twp_gitea_repo', sanitize_text_field($_POST['twp_gitea_repo']));
|
||||
update_option('twp_gitea_token', sanitize_text_field($_POST['twp_gitea_token']));
|
||||
update_option('twp_twilio_api_key_sid', sanitize_text_field($_POST['twp_twilio_api_key_sid']));
|
||||
update_option('twp_twilio_api_key_secret', sanitize_text_field($_POST['twp_twilio_api_key_secret']));
|
||||
update_option('twp_fcm_push_credential_sid', sanitize_text_field($_POST['twp_fcm_push_credential_sid']));
|
||||
|
||||
$settings_saved = true;
|
||||
}
|
||||
@@ -66,9 +63,6 @@ $fcm_sa_configured = !empty($fcm_service_account_json) && !empty($fcm_project_id
|
||||
$auto_update_enabled = get_option('twp_auto_update_enabled', '1') === '1';
|
||||
$gitea_repo = get_option('twp_gitea_repo', 'wp-plugins/twilio-wp-plugin');
|
||||
$gitea_token = get_option('twp_gitea_token', '');
|
||||
$twilio_api_key_sid = get_option('twp_twilio_api_key_sid', '');
|
||||
$twilio_api_key_secret = get_option('twp_twilio_api_key_secret', '');
|
||||
$fcm_push_credential_sid = get_option('twp_fcm_push_credential_sid', '');
|
||||
|
||||
// Get update status
|
||||
require_once TWP_PLUGIN_DIR . 'includes/class-twp-auto-updater.php';
|
||||
@@ -177,53 +171,6 @@ $total_sessions = $wpdb->get_var("SELECT COUNT(*) FROM $sessions_table");
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="twp_twilio_api_key_sid">Twilio API Key SID</label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="text"
|
||||
id="twp_twilio_api_key_sid"
|
||||
name="twp_twilio_api_key_sid"
|
||||
value="<?php echo esc_attr($twilio_api_key_sid); ?>"
|
||||
class="regular-text"
|
||||
placeholder="SK...">
|
||||
<p class="description">
|
||||
Create an API Key in Twilio Console > Account > API Keys. Required for mobile VoIP tokens.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="twp_twilio_api_key_secret">Twilio API Key Secret</label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="password"
|
||||
id="twp_twilio_api_key_secret"
|
||||
name="twp_twilio_api_key_secret"
|
||||
value="<?php echo esc_attr($twilio_api_key_secret); ?>"
|
||||
class="regular-text">
|
||||
<p class="description">
|
||||
The secret associated with the API Key SID above. Shown only once when key is created.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="twp_fcm_push_credential_sid">Push Credential SID</label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="text"
|
||||
id="twp_fcm_push_credential_sid"
|
||||
name="twp_fcm_push_credential_sid"
|
||||
value="<?php echo esc_attr($fcm_push_credential_sid); ?>"
|
||||
class="regular-text"
|
||||
placeholder="CR...">
|
||||
<p class="description">
|
||||
Twilio Push Credential SID. Create in Twilio Console > Messaging > Push Credentials using your FCM service account JSON. Required for incoming call push notifications.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php if ($fcm_sa_configured): ?>
|
||||
|
||||
@@ -211,44 +211,41 @@ class TWP_Mobile_API {
|
||||
global $wpdb;
|
||||
$queues_table = $wpdb->prefix . 'twp_call_queues';
|
||||
$calls_table = $wpdb->prefix . 'twp_queued_calls';
|
||||
$assignments_table = $wpdb->prefix . 'twp_queue_assignments';
|
||||
$groups_table = $wpdb->prefix . 'twp_group_members';
|
||||
|
||||
// Get queues assigned to this user
|
||||
$queue_ids = $wpdb->get_col($wpdb->prepare(
|
||||
"SELECT queue_id FROM $assignments_table WHERE user_id = %d",
|
||||
// Auto-create personal queues if they don't exist
|
||||
$extensions_table = $wpdb->prefix . 'twp_user_extensions';
|
||||
$existing_extension = $wpdb->get_row($wpdb->prepare(
|
||||
"SELECT extension FROM $extensions_table WHERE user_id = %d",
|
||||
$user_id
|
||||
));
|
||||
|
||||
// Also include personal queues
|
||||
$personal_queue_ids = $wpdb->get_col($wpdb->prepare(
|
||||
"SELECT id FROM $queues_table WHERE user_id = %d",
|
||||
$user_id
|
||||
));
|
||||
|
||||
$all_queue_ids = array_unique(array_merge($queue_ids, $personal_queue_ids));
|
||||
|
||||
if (empty($all_queue_ids)) {
|
||||
return new WP_REST_Response(array(
|
||||
'success' => true,
|
||||
'queues' => array()
|
||||
), 200);
|
||||
if (!$existing_extension) {
|
||||
TWP_User_Queue_Manager::create_user_queues($user_id);
|
||||
}
|
||||
|
||||
$queue_ids_str = implode(',', array_map('intval', $all_queue_ids));
|
||||
|
||||
// Get queue information with call counts
|
||||
$queues = $wpdb->get_results("
|
||||
SELECT
|
||||
// Get queues where user is a member of the assigned agent group OR personal/hold queues
|
||||
$queues = $wpdb->get_results($wpdb->prepare("
|
||||
SELECT DISTINCT
|
||||
q.id,
|
||||
q.queue_name,
|
||||
q.queue_type,
|
||||
q.extension,
|
||||
COUNT(c.id) as waiting_count
|
||||
FROM $queues_table q
|
||||
LEFT JOIN $groups_table gm ON gm.group_id = q.agent_group_id
|
||||
LEFT JOIN $calls_table c ON q.id = c.queue_id AND c.status = 'waiting'
|
||||
WHERE q.id IN ($queue_ids_str)
|
||||
WHERE (gm.user_id = %d AND gm.is_active = 1)
|
||||
OR (q.user_id = %d AND q.queue_type IN ('personal', 'hold'))
|
||||
GROUP BY q.id
|
||||
");
|
||||
ORDER BY
|
||||
CASE
|
||||
WHEN q.queue_type = 'personal' THEN 1
|
||||
WHEN q.queue_type = 'hold' THEN 2
|
||||
ELSE 3
|
||||
END,
|
||||
q.queue_name ASC
|
||||
", $user_id, $user_id));
|
||||
|
||||
$result = array();
|
||||
foreach ($queues as $queue) {
|
||||
@@ -689,42 +686,25 @@ class TWP_Mobile_API {
|
||||
public function get_voice_token($request) {
|
||||
$user_id = $this->auth->get_current_user_id();
|
||||
$user = get_userdata($user_id);
|
||||
$identity = 'agent' . $user_id . preg_replace('/[^a-zA-Z0-9]/', '', $user->user_login);
|
||||
|
||||
$account_sid = get_option('twp_twilio_account_sid');
|
||||
$auth_token = get_option('twp_twilio_auth_token');
|
||||
$api_key_sid = get_option('twp_twilio_api_key_sid');
|
||||
$api_key_secret = get_option('twp_twilio_api_key_secret');
|
||||
$twiml_app_sid = get_option('twp_twiml_app_sid');
|
||||
$push_credential_sid = get_option('twp_fcm_push_credential_sid');
|
||||
|
||||
if (empty($api_key_sid) || empty($api_key_secret)) {
|
||||
return new WP_Error('missing_api_key', 'Twilio API Key SID and Secret must be configured', array('status' => 500));
|
||||
$clean_name = preg_replace('/[^a-zA-Z0-9]/', '', $user->user_login);
|
||||
if (empty($clean_name)) {
|
||||
$clean_name = 'user';
|
||||
}
|
||||
$identity = 'agent' . $user_id . $clean_name;
|
||||
|
||||
try {
|
||||
$token = new \Twilio\Jwt\AccessToken(
|
||||
$account_sid,
|
||||
$api_key_sid,
|
||||
$api_key_secret,
|
||||
3600,
|
||||
$identity
|
||||
);
|
||||
require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-twp-twilio-api.php';
|
||||
$twilio = new TWP_Twilio_API();
|
||||
$result = $twilio->generate_capability_token($identity);
|
||||
|
||||
$voiceGrant = new \Twilio\Jwt\Grants\VoiceGrant();
|
||||
$voiceGrant->setOutgoingApplicationSid($twiml_app_sid);
|
||||
$voiceGrant->setIncomingAllow(true);
|
||||
|
||||
if (!empty($push_credential_sid)) {
|
||||
$voiceGrant->setPushCredentialSid($push_credential_sid);
|
||||
if (!$result['success']) {
|
||||
return new WP_Error('token_error', $result['error'], array('status' => 500));
|
||||
}
|
||||
|
||||
$token->addGrant($voiceGrant);
|
||||
|
||||
return new WP_REST_Response(array(
|
||||
'token' => $token->toJWT(),
|
||||
'identity' => $identity,
|
||||
'expires_in' => 3600
|
||||
'token' => $result['data']['token'],
|
||||
'identity' => $result['data']['client_name'],
|
||||
'expires_in' => $result['data']['expires_in']
|
||||
), 200);
|
||||
|
||||
} catch (Exception $e) {
|
||||
|
||||
@@ -142,38 +142,40 @@ class TWP_Mobile_SSE {
|
||||
global $wpdb;
|
||||
$queues_table = $wpdb->prefix . 'twp_call_queues';
|
||||
$calls_table = $wpdb->prefix . 'twp_queued_calls';
|
||||
$assignments_table = $wpdb->prefix . 'twp_queue_assignments';
|
||||
$groups_table = $wpdb->prefix . 'twp_group_members';
|
||||
|
||||
// Get queue IDs
|
||||
$queue_ids = $wpdb->get_col($wpdb->prepare(
|
||||
"SELECT queue_id FROM $assignments_table WHERE user_id = %d",
|
||||
// Auto-create personal queues if they don't exist
|
||||
$extensions_table = $wpdb->prefix . 'twp_user_extensions';
|
||||
$existing_extension = $wpdb->get_row($wpdb->prepare(
|
||||
"SELECT extension FROM $extensions_table WHERE user_id = %d",
|
||||
$user_id
|
||||
));
|
||||
|
||||
$personal_queue_ids = $wpdb->get_col($wpdb->prepare(
|
||||
"SELECT id FROM $queues_table WHERE user_id = %d",
|
||||
$user_id
|
||||
));
|
||||
|
||||
$all_queue_ids = array_unique(array_merge($queue_ids, $personal_queue_ids));
|
||||
|
||||
if (empty($all_queue_ids)) {
|
||||
return array();
|
||||
if (!$existing_extension) {
|
||||
TWP_User_Queue_Manager::create_user_queues($user_id);
|
||||
}
|
||||
|
||||
$queue_ids_str = implode(',', array_map('intval', $all_queue_ids));
|
||||
|
||||
$queues = $wpdb->get_results("
|
||||
SELECT
|
||||
// Get queues where user is a member of the assigned agent group OR personal/hold queues
|
||||
$queues = $wpdb->get_results($wpdb->prepare("
|
||||
SELECT DISTINCT
|
||||
q.id,
|
||||
q.queue_name,
|
||||
COUNT(c.id) as waiting_count,
|
||||
MIN(c.enqueued_at) as oldest_call_time
|
||||
FROM $queues_table q
|
||||
LEFT JOIN $groups_table gm ON gm.group_id = q.agent_group_id
|
||||
LEFT JOIN $calls_table c ON q.id = c.queue_id AND c.status = 'waiting'
|
||||
WHERE q.id IN ($queue_ids_str)
|
||||
WHERE (gm.user_id = %d AND gm.is_active = 1)
|
||||
OR (q.user_id = %d AND q.queue_type IN ('personal', 'hold'))
|
||||
GROUP BY q.id
|
||||
");
|
||||
ORDER BY
|
||||
CASE
|
||||
WHEN q.queue_type = 'personal' THEN 1
|
||||
WHEN q.queue_type = 'hold' THEN 2
|
||||
ELSE 3
|
||||
END,
|
||||
q.queue_name ASC
|
||||
", $user_id, $user_id));
|
||||
|
||||
$result = array();
|
||||
foreach ($queues as $queue) {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"project_info": {
|
||||
"project_number": "000000000000",
|
||||
"project_id": "twp-softphone-placeholder",
|
||||
"storage_bucket": "twp-softphone-placeholder.appspot.com"
|
||||
"project_number": "187457540438",
|
||||
"project_id": "twp-softphone",
|
||||
"storage_bucket": "twp-softphone.firebasestorage.app"
|
||||
},
|
||||
"client": [
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:000000000000:android:0000000000000000",
|
||||
"mobilesdk_app_id": "1:187457540438:android:d6d777270c23f6660946f7",
|
||||
"android_client_info": {
|
||||
"package_name": "io.cloudhosting.twp.twp_softphone"
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
"oauth_client": [],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "PLACEHOLDER_API_KEY"
|
||||
"current_key": "AIzaSyAdGJrWPy9b9arqHnlY5G_hsGiDcm6cchA"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
|
||||
@@ -17,11 +17,11 @@ class AgentStatus {
|
||||
|
||||
factory AgentStatus.fromJson(Map<String, dynamic> json) {
|
||||
return AgentStatus(
|
||||
status: _parseStatus(json['status'] as String),
|
||||
isLoggedIn: json['is_logged_in'] as bool,
|
||||
status: _parseStatus((json['status'] ?? 'offline') as String),
|
||||
isLoggedIn: json['is_logged_in'] == true || json['is_logged_in'] == 1 || json['is_logged_in'] == '1',
|
||||
currentCallSid: json['current_call_sid'] as String?,
|
||||
lastActivity: json['last_activity'] as String?,
|
||||
availableForQueues: json['available_for_queues'] as bool? ?? true,
|
||||
availableForQueues: json['available_for_queues'] != false && json['available_for_queues'] != 0 && json['available_for_queues'] != '0',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,13 +15,19 @@ class QueueInfo {
|
||||
|
||||
factory QueueInfo.fromJson(Map<String, dynamic> json) {
|
||||
return QueueInfo(
|
||||
id: json['id'] as int,
|
||||
name: json['name'] as String,
|
||||
type: json['type'] as String,
|
||||
id: _toInt(json['id']),
|
||||
name: (json['name'] ?? '') as String,
|
||||
type: (json['type'] ?? '') as String,
|
||||
extension: json['extension'] as String?,
|
||||
waitingCount: json['waiting_count'] as int,
|
||||
waitingCount: _toInt(json['waiting_count']),
|
||||
);
|
||||
}
|
||||
|
||||
static int _toInt(dynamic value) {
|
||||
if (value is int) return value;
|
||||
if (value is String) return int.tryParse(value) ?? 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
class QueueCall {
|
||||
@@ -43,12 +49,18 @@ class QueueCall {
|
||||
|
||||
factory QueueCall.fromJson(Map<String, dynamic> json) {
|
||||
return QueueCall(
|
||||
callSid: json['call_sid'] as String,
|
||||
fromNumber: json['from_number'] as String,
|
||||
toNumber: json['to_number'] as String,
|
||||
position: json['position'] as int,
|
||||
status: json['status'] as String,
|
||||
waitTime: json['wait_time'] as int,
|
||||
callSid: (json['call_sid'] ?? '') as String,
|
||||
fromNumber: (json['from_number'] ?? '') as String,
|
||||
toNumber: (json['to_number'] ?? '') as String,
|
||||
position: _toInt(json['position']),
|
||||
status: (json['status'] ?? '') as String,
|
||||
waitTime: _toInt(json['wait_time']),
|
||||
);
|
||||
}
|
||||
|
||||
static int _toInt(dynamic value) {
|
||||
if (value is int) return value;
|
||||
if (value is String) return int.tryParse(value) ?? 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,16 @@ class User {
|
||||
|
||||
factory User.fromJson(Map<String, dynamic> json) {
|
||||
return User(
|
||||
id: json['user_id'] as int,
|
||||
login: json['user_login'] as String,
|
||||
displayName: json['display_name'] as String,
|
||||
id: _toInt(json['user_id']),
|
||||
login: (json['user_login'] ?? '') as String,
|
||||
displayName: (json['display_name'] ?? '') as String,
|
||||
email: json['email'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
static int _toInt(dynamic value) {
|
||||
if (value is int) return value;
|
||||
if (value is String) return int.tryParse(value) ?? 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,6 +103,15 @@ class CallProvider extends ChangeNotifier {
|
||||
|
||||
Future<void> sendDigits(String digits) => _voiceService.sendDigits(digits);
|
||||
|
||||
Future<void> makeCall(String number) async {
|
||||
_callInfo = _callInfo.copyWith(
|
||||
state: CallState.connecting,
|
||||
callerNumber: number,
|
||||
);
|
||||
notifyListeners();
|
||||
await _voiceService.makeCall(number);
|
||||
}
|
||||
|
||||
Future<void> holdCall() async {
|
||||
final sid = _callInfo.callSid;
|
||||
if (sid == null) return;
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:provider/provider.dart';
|
||||
import '../providers/agent_provider.dart';
|
||||
import '../providers/call_provider.dart';
|
||||
import '../widgets/agent_status_toggle.dart';
|
||||
import '../widgets/dialpad.dart';
|
||||
import '../widgets/queue_card.dart';
|
||||
import 'active_call_screen.dart';
|
||||
import 'settings_screen.dart';
|
||||
@@ -23,6 +24,90 @@ class _DashboardScreenState extends State<DashboardScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
void _showDialer(BuildContext context) {
|
||||
final numberController = TextEditingController();
|
||||
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
||||
),
|
||||
builder: (ctx) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.of(ctx).viewInsets.bottom,
|
||||
top: 16,
|
||||
left: 16,
|
||||
right: 16,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Number display
|
||||
TextField(
|
||||
controller: numberController,
|
||||
keyboardType: TextInputType.phone,
|
||||
autofillHints: const [AutofillHints.telephoneNumber],
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(ctx).textTheme.headlineSmall,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Enter phone number',
|
||||
suffixIcon: IconButton(
|
||||
icon: const Icon(Icons.backspace_outlined),
|
||||
onPressed: () {
|
||||
final text = numberController.text;
|
||||
if (text.isNotEmpty) {
|
||||
numberController.text =
|
||||
text.substring(0, text.length - 1);
|
||||
numberController.selection = TextSelection.fromPosition(
|
||||
TextPosition(offset: numberController.text.length),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// Dialpad
|
||||
Dialpad(
|
||||
onDigit: (digit) {
|
||||
numberController.text += digit;
|
||||
numberController.selection = TextSelection.fromPosition(
|
||||
TextPosition(offset: numberController.text.length),
|
||||
);
|
||||
},
|
||||
onClose: () => Navigator.pop(ctx),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
// Call button
|
||||
ElevatedButton.icon(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.green,
|
||||
foregroundColor: Colors.white,
|
||||
minimumSize: const Size(double.infinity, 48),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
),
|
||||
),
|
||||
icon: const Icon(Icons.call),
|
||||
label: const Text('Call'),
|
||||
onPressed: () {
|
||||
final number = numberController.text.trim();
|
||||
if (number.isNotEmpty) {
|
||||
context.read<CallProvider>().makeCall(number);
|
||||
Navigator.pop(ctx);
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final agent = context.watch<AgentProvider>();
|
||||
@@ -58,6 +143,10 @@ class _DashboardScreenState extends State<DashboardScreen> {
|
||||
),
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () => _showDialer(context),
|
||||
child: const Icon(Icons.phone),
|
||||
),
|
||||
body: RefreshIndicator(
|
||||
onRefresh: () => agent.refresh(),
|
||||
child: ListView(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../providers/auth_provider.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
@@ -39,6 +40,7 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
serverUrl = 'https://$serverUrl';
|
||||
}
|
||||
|
||||
TextInput.finishAutofillContext();
|
||||
context.read<AuthProvider>().login(
|
||||
serverUrl,
|
||||
_usernameController.text.trim(),
|
||||
@@ -55,7 +57,8 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
child: Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Form(
|
||||
child: AutofillGroup(
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -80,6 +83,7 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
keyboardType: TextInputType.url,
|
||||
autofillHints: const [AutofillHints.url],
|
||||
validator: (v) =>
|
||||
v == null || v.trim().isEmpty ? 'Required' : null,
|
||||
),
|
||||
@@ -91,6 +95,7 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
prefixIcon: Icon(Icons.person),
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
autofillHints: const [AutofillHints.username],
|
||||
validator: (v) =>
|
||||
v == null || v.trim().isEmpty ? 'Required' : null,
|
||||
),
|
||||
@@ -110,6 +115,7 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
),
|
||||
),
|
||||
obscureText: _obscurePassword,
|
||||
autofillHints: const [AutofillHints.password],
|
||||
validator: (v) =>
|
||||
v == null || v.isEmpty ? 'Required' : null,
|
||||
),
|
||||
@@ -142,6 +148,7 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -62,6 +62,10 @@ class VoiceService {
|
||||
await TwilioVoice.instance.call.toggleSpeaker(speaker);
|
||||
}
|
||||
|
||||
Future<bool> makeCall(String to) async {
|
||||
return await TwilioVoice.instance.call.place(to: to, from: _identity ?? '') ?? false;
|
||||
}
|
||||
|
||||
Future<void> sendDigits(String digits) async {
|
||||
await TwilioVoice.instance.call.sendDigits(digits);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user