testing progress
This commit is contained in:
@@ -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()
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user