Here's my js script file, specifically the if statement used to add too my chatbots messages. This is then output on a separate html frontend chat bot window. how can i make this snippet of code show up on the html file? I know JavaScript well enough so this seemed like a simple thing to do, but now I've hit a brick wall with my current knowledge. I have tried putting the script inside the ${data.message} variable within my python web api but to no avail.
if(data.message.includes("Great now, heres our payment portal, once the payment has been confirmed I shall book you in.<br>"))
{
$('.chat-window').append(`
<li class="right clearfix">
<div class="chat-body clearfix">
<div class="header">
<strong class="pull-left primary-font">Peggy</strong><br>
</div>
<p>
${data.message}<br> Doing the thing
<img alt="Checkout" class="v-button" role="button" src="www.example.com/sandbox"/>
<script type="text/javascript" src="www.example.com/sandbox"></script>
</p>
</div>
</li>
`)
}
else {
$('.chat-window').append(`
<li class="right clearfix">
<div class="chat-body clearfix">
<div class="header">
<strong class="pull-left primary-font">Peggy</strong><br>
</div>
<p>
${data.message}
</p>
</div>
</li>
`)
^^ js script file
\/ html file
<div class="panel-body">
<ul class="chat-window">
<li class="right clearfix">
<div class="chat-body clearfix">
<div class="header">
<strong class="pull-left primary-font">Peggy: </strong><br>
</div>
<p>
Hi my name is Peggy Booking assistant, how can I assist you today?
</p>
</div>
</li>
</ul>
</div>
Basically I'm asking how do i add the <script type="text/js" src="example.com/sandbox"> <script/> to my main html file in the browser after the page has loaded inside the <div class"chat-window">. I can get the image to show up just fine using the data.message object, its just the script. a week of googling has not helped.
src="www.example.com/sandbox"will likely result in an attempt to get the script fromhttp://baseURL/www.example.com/sandbox, which may more may not be what you want.