<?php 
    $answer = 'Halo. Ada yang bisa saya bantu?';

    if(isset($_POST['submit']))
    {
        $say = rawurlencode($_POST['say']);
        $json = file_get_contents("http://xxx/conversation_start.php?bot_id=1&say=".$say."");
        $json_data = json_decode($json); 
        $answer = $json_data->botsay; 
    }
?>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Chatbot with Voice Answer</title>

    </head>

    <body>
        <script type='text/javascript' src="https://www.botlibre.com/scripts/sdk.js"></script>
        <script type='text/javascript'>
            SDK.applicationId = "8877781453080156235";
            var sdk = new SDKConnection();
            var web = new WebAvatar();
            web.version = 8.5;
            web.connection = sdk;
            web.avatar = "20697301";
            web.voice = "cmu-slt";
            web.voiceMod = "default";
            web.nativeVoice = true;
            web.nativeVoiceName = "Google Bahasa Indonesia";
            web.lang = "id-ID";
            web.width = "330";
            web.createBox();
            web.addMessage("<?php echo $answer; ?>", "", "", "");
            web.processMessages();
        </script>
        <br>
        <label>Tuliskan percakapan:</label>
    
        <form method="POST" action=''>
            <input type='text' name='say' autofocus><br>
            <input type='submit' value='Kirim' name='submit' class='button'> 
        </form>
        <p>
            <?php 
                echo $answer; 
            ?>
        </p>
    
        <div class="inline">
            <div style="display: none;" id="waitingdiv">
                Memproses Jawaban.....<br>
            </div>
       
            <select id="voiceselection" style="display: none;">
                <option selected="selected" value="Indonesian Male">Indonesian Male</option>
            </select>

            <div style="display: block;" id="counterBox1" class="counterBox">
			
			    <input id="playbutton" value="Panggil" type="hidden">
			
                <input id="stopbutton" value="Berhenti" type="hidden"><br>
            </div>
        </div>
    
    </body>
</html>