testing progress

This commit is contained in:
2025-08-12 07:05:47 -07:00
parent 304b5de40b
commit 51dd3077d2
5 changed files with 2698 additions and 0 deletions

View File

@@ -654,4 +654,55 @@ class TWP_Twilio_API {
];
}
}
/**
* Generate capability token for Browser Phone
*/
public function generate_capability_token($client_name = null) {
$account_sid = get_option('twp_twilio_account_sid');
$auth_token = get_option('twp_twilio_auth_token');
$twiml_app_sid = get_option('twp_twiml_app_sid');
if (empty($account_sid) || empty($auth_token)) {
return [
'success' => false,
'error' => 'Twilio credentials not configured'
];
}
if (empty($twiml_app_sid)) {
return [
'success' => false,
'error' => 'TwiML App SID not configured. Please set up a TwiML App in your Twilio Console.'
];
}
try {
// Create client name if not provided
if (!$client_name) {
$current_user = wp_get_current_user();
$client_name = 'agent_' . $current_user->ID . '_' . sanitize_title($current_user->display_name);
}
$capability = new \Twilio\Jwt\ClientToken($account_sid, $auth_token);
$capability->allowClientOutgoing($twiml_app_sid);
$capability->allowClientIncoming($client_name);
$token = $capability->generateToken(3600); // Valid for 1 hour
return [
'success' => true,
'data' => [
'token' => $token,
'client_name' => $client_name,
'expires_in' => 3600
]
];
} catch (\Exception $e) {
return [
'success' => false,
'error' => 'Failed to generate capability token: ' . $e->getMessage()
];
}
}
}