add_action('wp_ajax_bp_ai_property_search_realtime_session', 'bp_ai_property_search_realtime_session');
add_action('wp_ajax_nopriv_bp_ai_property_search_realtime_session', 'bp_ai_property_search_realtime_session');
function bp_ai_property_search_realtime_session() {
$nonce = isset($_POST['nonce']) ? sanitize_text_field(wp_unslash($_POST['nonce'])) : '';
if (!wp_verify_nonce($nonce, 'bp_property_ai_nonce')) {
wp_send_json_error(array('message' => 'Security check failed. Please refresh the page.'));
}
if (!defined('OPENAI_API_KEY') || empty(OPENAI_API_KEY) || OPENAI_API_KEY === 'PASTE_YOUR_OPENAI_KEY_HERE') {
wp_send_json_error(array('message' => 'OpenAI API key is missing in wp-config.php.'));
}
$instructions = '
You are Best-Property.ae AI Property Search Assistant.
You help buyers, tenants, investors and property seekers find properties in Dubai and across the UAE.
You understand all languages and reply in the same language used by the visitor unless they ask otherwise.
Your job:
- Ask what type of property the visitor wants.
- Understand buy, rent, commercial, land and off-plan requests.
- Extract location, city, community, budget, bedrooms, bathrooms, property type and purpose.
- Ask one short question at a time.
- Do not ask again for information already given.
- Be friendly, clear and professional.
- Keep answers short and useful.
- Help the visitor search properties on Best-Property.ae.
- Never ask for private financial information.
';
$session_payload = array(
'session' => array(
'type' => 'realtime',
'model' => 'gpt-realtime-2',
'instructions' => $instructions,
'audio' => array(
'output' => array(
'voice' => 'marin',
),
'input' => array(
'transcription' => array(
'model' => 'gpt-4o-mini-transcribe',
),
'turn_detection' => array(
'type' => 'server_vad',
'threshold' => 0.5,
'prefix_padding_ms' => 300,
'silence_duration_ms' => 700,
),
),
),
),
);
$response = wp_remote_post('https://api.openai.com/v1/realtime/client_secrets', array(
'timeout' => 30,
'headers' => array(
'Authorization' => 'Bearer ' . OPENAI_API_KEY,
'Content-Type' => 'application/json',
'OpenAI-Safety-Identifier' => 'bp-property-search-visitor',
),
'body' => wp_json_encode($session_payload),
));
if (is_wp_error($response)) {
wp_send_json_error(array('message' => $response->get_error_message()));
}
$status_code = wp_remote_retrieve_response_code($response);
$body = wp_remote_retrieve_body($response);
$data = json_decode($body, true);
if ($status_code < 200 || $status_code >= 300) {
wp_send_json_error(array(
'message' => 'OpenAI realtime property search session failed.',
'status' => $status_code,
'raw' => $body,
));
}
if (empty($data['value'])) {
wp_send_json_error(array(
'message' => 'OpenAI realtime client secret was not returned.',
'raw' => $body,
));
}
wp_send_json_success(array(
'client_secret' => $data['value'],
'session' => isset($data['session']) ? $data['session'] : array(),
));
}
Chandigarh Pleasure - Best Property
About Chandigarh Pleasure
Investigate Independent Chandigarh escorts who are open for personal appointments, romantic dates, and social events. Find nearby choices throughout Chandigarh with detailed profiles and straightforward means of contacting them directly.
Sort by:
Default Order
Date Old to New
Date New to Old
Rating (Low to High)
Rating (High to Low)
Leave a Review