How to access value in JS file stored using PHP function
<p>I'm building a custom plugin for a chatbot in WordPress, where I've written some logic in a JS file to get the API and responses. As request body I am sending two parameters. One of the parameters is stored in the wp database using a PHP function (my core plugin file). So I want to access that function/that value in my JS file so I can send it in the API request. </p><p>JS function -</p><p><br /></p>
<pre class="brush:php;toolbar:false;">fetch('https://whatgpt.up.railway.app/api/query-train-gpt', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: userMessage,
number: phoneNumber,
}),
})</pre>
<p>Backend PHP functions -</p>
<pre class="brush:php;toolbar:false;">function get_admin_phone_number()
{
// Retrieve the stored admin phone number from the database.
$admin_phone_number = get_option('admin_phone_number', ''); // Provide a default value if the option is not set.
// Return the admin phone number.
return $admin_phone_number;
}</pre>
<p><br /></p>