Compare commits
1 Commits
2026.03.06
...
2026.03.06
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d41b6aa535 |
@@ -52,8 +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_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_repo', sanitize_text_field($_POST['twp_gitea_repo']));
|
||||||
update_option('twp_gitea_token', sanitize_text_field($_POST['twp_gitea_token']));
|
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']));
|
|
||||||
|
|
||||||
$settings_saved = true;
|
$settings_saved = true;
|
||||||
}
|
}
|
||||||
@@ -65,8 +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';
|
$auto_update_enabled = get_option('twp_auto_update_enabled', '1') === '1';
|
||||||
$gitea_repo = get_option('twp_gitea_repo', 'wp-plugins/twilio-wp-plugin');
|
$gitea_repo = get_option('twp_gitea_repo', 'wp-plugins/twilio-wp-plugin');
|
||||||
$gitea_token = get_option('twp_gitea_token', '');
|
$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', '');
|
|
||||||
|
|
||||||
// Get update status
|
// Get update status
|
||||||
require_once TWP_PLUGIN_DIR . 'includes/class-twp-auto-updater.php';
|
require_once TWP_PLUGIN_DIR . 'includes/class-twp-auto-updater.php';
|
||||||
@@ -175,37 +171,6 @@ $total_sessions = $wpdb->get_var("SELECT COUNT(*) FROM $sessions_table");
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</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>
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<?php if ($fcm_sa_configured): ?>
|
<?php if ($fcm_sa_configured): ?>
|
||||||
|
|||||||
@@ -689,37 +689,25 @@ class TWP_Mobile_API {
|
|||||||
public function get_voice_token($request) {
|
public function get_voice_token($request) {
|
||||||
$user_id = $this->auth->get_current_user_id();
|
$user_id = $this->auth->get_current_user_id();
|
||||||
$user = get_userdata($user_id);
|
$user = get_userdata($user_id);
|
||||||
$identity = 'agent' . $user_id . preg_replace('/[^a-zA-Z0-9]/', '', $user->user_login);
|
$clean_name = preg_replace('/[^a-zA-Z0-9]/', '', $user->user_login);
|
||||||
|
if (empty($clean_name)) {
|
||||||
$account_sid = get_option('twp_twilio_account_sid');
|
$clean_name = 'user';
|
||||||
$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');
|
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
$identity = 'agent' . $user_id . $clean_name;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$token = new \Twilio\Jwt\AccessToken(
|
require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-twp-twilio-api.php';
|
||||||
$account_sid,
|
$twilio = new TWP_Twilio_API();
|
||||||
$api_key_sid,
|
$result = $twilio->generate_capability_token($identity);
|
||||||
$api_key_secret,
|
|
||||||
3600,
|
|
||||||
$identity
|
|
||||||
);
|
|
||||||
|
|
||||||
$voiceGrant = new \Twilio\Jwt\Grants\VoiceGrant();
|
if (!$result['success']) {
|
||||||
$voiceGrant->setOutgoingApplicationSid($twiml_app_sid);
|
return new WP_Error('token_error', $result['error'], array('status' => 500));
|
||||||
$voiceGrant->setIncomingAllow(true);
|
}
|
||||||
|
|
||||||
$token->addGrant($voiceGrant);
|
|
||||||
|
|
||||||
return new WP_REST_Response(array(
|
return new WP_REST_Response(array(
|
||||||
'token' => $token->toJWT(),
|
'token' => $result['data']['token'],
|
||||||
'identity' => $identity,
|
'identity' => $result['data']['client_name'],
|
||||||
'expires_in' => 3600
|
'expires_in' => $result['data']['expires_in']
|
||||||
), 200);
|
), 200);
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user