var botui = null; var cvsbuttons = []; var action = []; var message = ''; var param = ''; var kbn = ''; var text = ''; var userid = ''; var count = 0; var preventScroll={ x:0, y:0, setPos: function(){ this.x=window.pageXOffset; this.y=window.pageYOffset; }, handleEvent: function(){ window.scrollTo(this.x,this.y); }, enable: function(){ this.setPos(); window.addEventListener('scroll',this); }, disable: function(){ window.removeEventListener('scroll',this); } }; var rebot = (function(){ var chat_window_tmpl = (function() {/* */}).toString().match(/\/\*([\s\S]*)\*\//)[1].replace(/\n|\r/g, ''); function htmlToElement(html) { var template = document.createElement('template'); template.innerHTML = html; if(template.content) { return template.content; } else{ return template.firstElementChild; } } return { onLoadEvent: function(){ userid = '1746791383'; var style = document.createElement('link'); style.setAttribute('style', 'text/css'); style.setAttribute('rel', 'stylesheet'); style.setAttribute('href', '//gyoseichatbot.azurewebsites.net/css/botui.min.css'); document.getElementsByTagName('head')[0].appendChild(style); style = document.createElement('link'); style.setAttribute('style', 'text/css'); style.setAttribute('rel', 'stylesheet'); style.setAttribute('href', '//gyoseichatbot.azurewebsites.net/css/botui-theme-default.css'); document.getElementsByTagName('head')[0].appendChild(style); $('head').append(''); var pDiv =document.body; var div =document.createElement('DIV'); div.id='div_chatbox'; pDiv.appendChild(div); var chat_window = htmlToElement(chat_window_tmpl); document.body.appendChild(chat_window); var txt = "" ; document.getElementById('div_chatbox').innerHTML = txt; var slide = $('#slide'); var contents = $('#slide-contents'); var aaa = $('#chat-app'); //開くボタン var openBtn = $('#open-btn img'); var btnOpenFlag = false; var openFlag = false; var panelSwitch = function() { //閉じる if (openFlag == true ) { slide.stop().animate({'width' : '200px','height' : '30px'}, 500); openBtn.show(); //開くボタンにする } //開く else if (openFlag == false) { slide.stop().animate({'width' : '400px','height' : '600px'}, 500); openBtn.hide(); //閉じるボタンにする } }; //開くボタンクリックしたら $('#open-btn').click(function(){ panelSwitch(); openFlag = !openFlag; btnOpenFlag = true; }); //画面下位置を取得 var bottomPos = $(document).height() - $(window).height() - 500; $(window).scroll(function () { if (!btnOpenFlag) { if ($(this).scrollTop() >= bottomPos) { if (openFlag == false) { panelSwitch(); openFlag = true; } } else { if (openFlag) { panelSwitch(); openFlag = false; } } } }); botload(); } }; })(); function botload(){ //var scripts = ['//www.promisejs.org/polyfills/promise-6.1.0.min.js', '//npmcdn.com/vue@2.0.5/dist/vue.min.js', '//unpkg.com/botui/build/botui.min.js']; var scripts = ['//www.promisejs.org/polyfills/promise-6.1.0.min.js', '//npmcdn.com/vue@2.0.5/dist/vue.min.js', '//gyoseichatbot.azurewebsites.net/js/botui.min.js']; //var scripts = ['//npmcdn.com/vue@2.0.5/dist/vue.min.js', '//unpkg.com/botui/build/botui.min.js']; var len = scripts.length; var i = 0; (function appendScript() { var script = document.createElement('script'); if(i < scripts.length){ script.src = scripts[i]; document.body.appendChild(script); } if (i++ < len) { script.onload = appendScript; }else{ script.onload = botstart(); } })(); } function botstart(){ if(2 == 1){ document.getElementById('slide').style.display='block'; botui = new BotUI('chat-appf'); }else{ /* var userAgent = window.navigator.userAgent.toLowerCase(); if(userAgent.indexOf('msie') != -1 || userAgent.indexOf('trident') != -1 ) { document.getElementById('slide').style.display='block'; document.getElementById('chat-app').style.display='none'; botui = new BotUI('chat-appf'); }else{ document.getElementById('chat-app').style.display='block'; document.getElementById('slide').style.display='none'; botui = new BotUI('chat-app'); } */ document.getElementById('chat-app').style.display='block'; document.getElementById('slide').style.display='none'; botui = new BotUI('chat-app'); } callsv(); } function botmess(){ if(cvsbuttons.length <= 1){ botui.message.bot({ photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', content: 'お問い合わせありがとうございます。' }).then(sonota(cvsbuttons[0]['value'])); }else{ action = []; for(var i=0; i < cvsbuttons.length; i++){ action.push({text: cvsbuttons[i]['text'],value: cvsbuttons[i]['value']}); } preventScroll.enable(); botui.message.bot({ photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', content: 'お問い合わせありがとうございます。' }).then(init); } } function init() { botui.message.bot({ delay: 1500, //メッセージの表示タイミングをずらす photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', content: 'はじめに問い合わせを行うジャンルを選択してください。' }).then(function() { window.setTimeout('preventScroll.disable()', 1100); return botui.action.button({ delay: 1000, action: action }); }).then(function(res) { movec(); sonota(res.value); }) } function callsv(){ $.ajax({ url: 'https://gyoseichatbot.azurewebsites.net/api/chatbox/init', type: 'POST', dataType: 'JSON', data:{ 'citycode' : '35000', 'id' : '1', } }).done(function(response){ cvsbuttons = response.cvsbuttons; botmess(); }).fail(function(XMLHttpRequest, textStatus, errorThrown){ alert('ボットデータの取得に失敗しました1'); }); } function sonota(param){ callWatson(param, '0', '初回発話'); } function chatcont(res,param){ if(res.value == 'chat_init'){ dispclear(); }else{ callWatson(param, '1', res.value); } } function callWatson(param, kbn, text){ param = param; kbn = kbn; text = text; $.ajax({ url: 'https://gyoseichatbot.azurewebsites.net/api/chatbox/conv', type: 'POST', dataType: 'JSON', data:{ 'citycode' : '35000', 'id' : '1', 'param' : param, 'kbn' : kbn, 'text' : text, 'userid' : userid, } }).done(function(response){ message = response.text; if(Object.keys(response.anseva).length > 0){ displayAnsevaMessage(param,response.anseva); }else if(Object.keys(response.cvsbuttons).length > 0){ displayChoiceMessage(param,response.cvsbuttons); }else{ //2019001 add start-- if(response.aitype ==1){ if(kbn ==1){ chordship(response,param); }else{ botui.message.bot({ delay: 1000, photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', content: message }).then(function() { return botui.action.text({ delay: 1000, action: { placeholder: '入力してください' } }); }).then(function(res) { chatcont(res,param); }) } }else{ //2019001 add end //2022001 ADD START------------------- if(response.typeNum ==27){ gspdisplayMessage(param); //2022001 ADD END--------------------- }else if(response.typeNum ==31){ questionnaireMessage(param); }else{ displayMessage(param); } } } }).fail(function(XMLHttpRequest, textStatus, errorThrown){ alert('ボットデータの取得に失敗しました2'); }); preventScroll.enable(); } function questionnaireMessage(param){ preventScroll.enable(); var messagedata = message[0].split('`'); botui.message.bot({ photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', content: messagedata[1] }).then(function() { window.setTimeout('preventScroll.disable()', 1100); return botui.action.text({ delay: 1000, action: { placeholder: '入力してください' } }); }).then(function(res) { movec(); chatcont(res,param); }) } //2022001 ADD START------------------- function gsepchat(param,text){ param = param; text = text; $.ajax({ url: 'https://gyoseichatbot.azurewebsites.net/api/chatbox/gsepchat', type: 'POST', dataType: 'JSON', data:{ 'citycode' : '35000', 'id' : '1', 'param' : param, 'text' : text, 'userid' : userid, } }).done(function(response){ message = response.text; var resmesslist=response.resmesslist; if(Object.keys(response.garbagebuttons).length > 0){ gspdisplayChoiceMessage(param,response.garbagebuttons); }else{ if(resmesslist.length =='1'){ botui.message.bot({ delay: 1000, photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', content: resmesslist[0] }).then(function() { return botui.action.text({ delay: 1000, action: { placeholder: '入力してください' } }); }).then(function(res) { gsepchat(param,res.value); }) }else if(resmesslist.length =='2'){ botui.message.bot({ delay: 1000, photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', content: resmesslist[0] }).then(function() { botui.message.bot({ delay: 1000, photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', content: resmesslist[1] }); }).then(function() { return botui.action.text({ delay: 1000, action: { placeholder: '入力してください' } }); }).then(function(res) { gsepchat(param,res.value); }) }else if(resmesslist.length =='3'){ botui.message.bot({ delay: 1000, photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', content: resmesslist[0] }).then(function() { botui.message.bot({ delay: 1000, photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', content: resmesslist[1] }); }).then(function() { botui.message.bot({ delay: 1000, photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', content: resmesslist[2] }); }).then(function() { return botui.action.text({ delay: 1000, action: { placeholder: '入力してください' } }); }).then(function(res) { gsepchat(param,res.value); }) } } }).fail(function(XMLHttpRequest, textStatus, errorThrown){ alert('ボットデータの取得に失敗しました'); }); preventScroll.enable(); } function gspdisplayMessage(param){ preventScroll.enable(); botui.message.bot({ photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', content: message }).then(function() { window.setTimeout('preventScroll.disable()', 1100); return botui.action.text({ delay: 1000, action: { placeholder: '入力してください' } }); }).then(function(res) { movec(); gsepchat(param,res.value); }) } function gspdisplayChoiceMessage(param,cvsbuttons) { action = []; for(var i=0; i < cvsbuttons.length; i++){ action.push({text: cvsbuttons[i]['text'],value: cvsbuttons[i]['value']}); } preventScroll.enable(); botui.message.bot({ delay: 500, //メッセージの表示タイミングをずらす photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', content: message }).then(function() { window.setTimeout('preventScroll.disable()', 1100); return botui.action.button({ delay: 1000, action: action }); }).then(function(res) { movec(); gsepchat(param,res.value); }) } //2022001 ADD END--------------------- //2019001 add start function chordship(response,param){ var contents = []; contents = response.contents; var action =[]; var type = contents[0]['type']; if(type=='text') { message = contents[0]['contents']; count = 1; if(contents.length > 1){ var goodbutton = contents[1]['button1']; var badbutton = contents[1]['button2']; var num = contents[1]['no']; var label = contents[1]['label']; var feedbackdata = {no: num,label: label,button1: goodbutton,button2: badbutton}; displayAnsevaMessage(param,feedbackdata); }else{ displayMessage(param); } }else if(type=='Error'){ message = contents[0]['contents']; count = 1; displayMessage(param); }else if(type=='button'){ var buttons =[]; buttons = contents[0]['contents']; text = contents[0]['text']; for(var i=0; i < buttons.length; i++){ action.push({text: buttons[i],value: '【selbut】'+buttons[i]}); } botui.message.bot({ photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', content: text }).then(function() { return botui.action.button({ delay: 1000, action: action }); }).then(function(res) { chatcont(res,param); }); } } //2019001 add end function displayMessage(param){ preventScroll.enable(); if(count == 0){ botui.message.bot({ photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', content: message }).then(function() { window.setTimeout('preventScroll.disable()', 1100); return botui.action.text({ delay: 1000, action: { placeholder: '入力してください' } }); }).then(function(res) { movec(); chatcont(res,param); }) }else{ botui.message.bot({ photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', content: message }).then(function() { window.setTimeout('preventScroll.disable()', 1100); return botui.action.button({ delay: 1000, action:[ { text: '続けて質問する', value: '1' }, { text: 'はじめに戻る', value: '2' } ] }); }).then(function(res) { movec(); if(res.value =='1'){ preventScroll.enable(); window.setTimeout('preventScroll.disable()', 1100); botui.action.text({ delay: 1000, action: { placeholder: '入力してください' } }).then(function(res) { movec(); chatcont(res,param); }) }else{ dispclear(); } }) } } function displayChoiceMessage(param,cvsbuttons) { action = []; for(var i=0; i < cvsbuttons.length; i++){ action.push({text: cvsbuttons[i]['text'],value: cvsbuttons[i]['value']}); } preventScroll.enable(); contents1 = message[0].split('`'); contents2 = message[1].split('`'); contents3 = message[2].split('`'); contents4 = message[3].split('`'); if(contents1[1] !== ''){ if(contents1[0].substring(0, 2) == '1'){ botui.message.bot({ photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', delay: 500, //メッセージの表示タイミングをずらす content: contents1[1] }); }else if(contents1[0].substring(0, 2) == '2'){ botui.message.bot({ photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', delay: 500, //メッセージの表示タイミングをずらす loading: true, content: '![product image](' + contents1[1] + ')' }); }else{ botui.message.bot({ photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', delay: 500, //メッセージの表示タイミングをずらす content: contents1 }); } } if(contents2[1] !== ''){ if(contents2[0].substring(0, 2) == '1'){ botui.message.bot({ photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', delay: 500, //メッセージの表示タイミングをずらす content: contents2[1] }); }else if(contents2[0].substring(0, 2) == '2'){ botui.message.bot({ photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', delay: 500, //メッセージの表示タイミングをずらす loading: true, content: '![product image](' + contents2[1] + ')' }); }else{ botui.message.bot({ photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', delay: 500, //メッセージの表示タイミングをずらす content: contents2 }); } } if(contents3[1] !== ''){ if(contents3[0].substring(0, 2) == '1'){ botui.message.bot({ photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', delay: 500, //メッセージの表示タイミングをずらす content: contents3[1] }); }else if(contents3[0].substring(0, 2) == '2'){ botui.message.bot({ photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', delay: 500, //メッセージの表示タイミングをずらす loading: true, content: '![product image](' + contents3[1] + ')' }); }else{ botui.message.bot({ photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', delay: 500, //メッセージの表示タイミングをずらす content: contents3 }); } } if(contents4[1] !== ''){ if(contents4[0].substring(0, 2) == '1'){ botui.message.bot({ photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', delay: 500, //メッセージの表示タイミングをずらす content: contents4[1] }); }else if(contents4[0].substring(0, 2) == '2'){ botui.message.bot({ photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', delay: 500, //メッセージの表示タイミングをずらす loading: true, content: '![product image](' + contents4[1] + ')' }); }else{ botui.message.bot({ photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', delay: 500, //メッセージの表示タイミングをずらす content: contents4 }); } } window.setTimeout('preventScroll.disable()', 1100); botui.action.button({ delay: 1000, action: action }).then(function(res) { movec(); chatcont(res,param); }); } function displayAnsevaMessage(param,anseva){ preventScroll.enable(); botui.message.bot({ photo: 'https://gyoseichatbot.blob.core.windows.net/35000/05.jpg', content: message }).then(function() { botui.message.add({ delay: 1000, //メッセージの表示タイミングをずらす content: anseva['label'] }); }).then(function() { var action = []; action.push({text: anseva['button1'],value: '1'}); action.push({text: anseva['button2'],value: '2'}); window.setTimeout('preventScroll.disable()', 1100); return botui.action.button({ delay: 1000, action: action }); }).then(function(res) { movec(); updateAnseva(param,anseva['no'],res.value); }) } function updateAnseva(param,no,success){ $.ajax({ url: 'https://gyoseichatbot.azurewebsites.net/api/chatbox/updateAnseva', type: 'POST', dataType: 'JSON', data:{ 'citycode' : '35000', 'id' : '1', 'no' : no, 'success' : success, } }).done(function(response){ message = response.text; displayMessage(param); }).fail(function(XMLHttpRequest, textStatus, errorThrown){ alert(errorThrown); }); } function dispclear(){ count = 0; botui.message.removeAll(); botui.action.hide(); var date = new Date(); userid = date.getTime(); botmess(); } if(document.readyState == 'complete'){ rebot.onLoadEvent(); } else { window.addEventListener('load', rebot.onLoadEvent, true); } function movec(){ if(2 == 2){ var targetElement = document.getElementById('chat-app') ; var clientRect = targetElement.getBoundingClientRect() ; var px = window.pageXOffset + clientRect.left ; var py = window.pageYOffset + clientRect.top ; window.scrollTo(-1000, py); } } $(window).on('unload', function(e) { $.ajax({ url: 'https://gyoseichatbot.azurewebsites.net/api/chatbox/delete', type: 'POST', dataType: 'JSON', data:{ 'citycode' : '35000', 'userid' : '1746791383', } }).done(function(response){ }).fail(function(XMLHttpRequest, textStatus, errorThrown){ alert(errorThrown); }); });