-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatBotBundle.js
More file actions
1 lines (1 loc) · 7.04 KB
/
Copy pathChatBotBundle.js
File metadata and controls
1 lines (1 loc) · 7.04 KB
1
class SysException{constructor(e){const t=new Error;return t.name="SysException",t.message=e,t}}!function(){const e=new showdown.Converter({tasklists:!0,emoji:!0}),t=new Audio;window.onUserInput=function(){},window.userInputText=function(e){if("object"!=typeof e)throw new SysException('The function "userInput" expected an HTMLElement tag <input> but was given a'+typeof e);if(e.value.length>0){const t=e.value;e.value="",window.createMsg(!0,t),window.onUserInput(t,"text")}},window.createMsg=function(n,o,s={}){if("boolean"!=typeof n)throw new BotException('The function "buildMsg" expected a boolean to parameter "sRight" but was given a'+typeof n);if("string"!=typeof o)throw new BotException('The function "buildMsg" expected a string to parameter "text" but was given a'+typeof n);if("object"!=typeof s)throw new BotException('The function "buildMsg" expected a object to parameter "media" but was given a'+typeof n);const i=n?"right":"left",c=document.createElement("li");c.classList.add(i);const a=document.createElement("span");a.classList.add("cb-msg",i);let d=void 0;"image"===s.type&&((d=document.createElement("img")).classList.add("media"),d.src=s.src);const r=document.createElement("p");r.classList.add("text"),r.innerHTML=e.makeHtml(o),void 0!==d&&a.appendChild(d),o.length>0&&a.appendChild(r);const l=document.createElement("time");l.classList.add("timestmap"),l.innerText=function(){const e=new Date;return(1==e.getHours().toString().length?"0"+e.getHours():e.getHours())+":"+(1==e.getMinutes().toString().length?"0"+e.getMinutes():e.getMinutes())}(),a.appendChild(l),c.appendChild(a),document.getElementById("ListMsg").appendChild(c),n||(t.src="/asset/notification.mp3",t.play()),window.scrollListMsg()},window.createToast=function(e){const t=document.createElement("li");t.classList.add("center");const n=document.createElement("span");n.classList.add("msg","center");const o=document.createElement("p");o.classList.add("text"),o.innerText=e,n.appendChild(o),t.appendChild(n),document.getElementById("ListMsg").appendChild(t)},window.scrollListMsg=function(e="end"){const t=document.querySelector(".cb-scroll");"end"===e&&setTimeout(()=>{t.scrollTo(0,t.scrollHeight)},200)},window.typingToggle=function(){const e=document.getElementById("StatusProfile");"online"===e.innerText?e.innerText="digitando...":e.innerText="online"}}();class BotException{constructor(e){const t=new Error;return t.name="BotException",t.message=e,t}}let acceptedMedias=["image"];class Bot{constructor(){function e(t){(function(e){if(void 0!==e.text&&"string"!=typeof e.text)return window.createToast(new BotException(`A sentenca com o seguinte valor no campo texto "${e.text}" deve estar entre aspas ("...") `)),!1;if(void 0!==e.next&&"number"!=typeof e.next)return window.createToast(new BotException(`A sentenca com o seguinte texto de referência "${e.text}" requer chama outra mensagem em sequência, porém o valor de next deve ser um número referente a posição da mensagem desejada`)),!1;if(void 0!==e.media){let t=e.media;if(!t.type||!t.src)return window.createToast(new BotException(`A sentenca com o seguinte texto de referência "${e.text}" requer conteudo de midía, porém o type ou o src não foi especificado!`)),!1;{if("string"!=typeof t.type)return window.createToast(new BotException(`A sentenca com o seguinte texto de referência "${e.text}" requer conteudo de midía, porém o type deve ter a palavra "image"`)),!1;let n=!1;for(let e of acceptedMedias)t.type===e&&(n=!0);if(!n)return window.createToast(new BotException(`A sentenca com o seguinte texto de referência "${e.text}" requer conteudo de midía, porém o type especificado não é válido`)),!1;if("string"!=typeof t.src)return window.createToast(new BotException(`A sentenca com o seguinte texto de referência "${e.text}" requer conteudo de midía, porém o src deve ser uma link`)),!1}}if(void 0!==e.awnsers){if("object"!=typeof e.awnsers)return window.createToast(new BotException(`A sentenca com o seguinte texto de referência "${e.text}" requer respostas, porém o mesmo não tem padrão [{...},{...}] !`)),!1;for(let t of e.awnsers){if("string"!=typeof t.pattern)return window.createToast(new BotException(`A sentenca com o seguinte texto de referência "${e.text}" requer resposta, porém o pattern deve estar entre aspas ("...")!`)),!1;if("function"!=typeof t.exec)return window.createToast(new BotException(`A sentenca com o seguinte texto de referência "${e.text}" requer resposta, porém o exec deve ser uma function(){...}, (parttern pertencente "${t.pattern}")`)),!1}}return!0})(t)&&(window.typingToggle(),setTimeout(()=>{o=t.awnsers,window.typingToggle(),window.createMsg(!1,t.text,t.media),void 0!==t.next&&e(window.sentences[t.next])},t.text.length*window.bottyping))}function t(t){let n=t.exec();if("number"==typeof n)return e(window.sentences[n])}function n(){"object"==typeof window.botstart&&e(window.botstart)}let o=void 0;window.onUserInput=(s=>{o?function(e){for(let i of o)if(n=e,s=i.pattern,new RegExp(s,"gmi").test(n))return t(i),!0;var n,s;return!1}(s)||e(window.notunderstand):n()}),n()}}window.Bot=Bot,document.getElementById("ChatBotWhatsApp").innerHTML+='\n<div id="BtnCallWhats">\n<div class="left"></div>\n<div class="center">\n <div class="text">\n <b>QUER PARTICIPAR DO GRUPO VIP?</b>\n <span>GRUPO VITALÍCIO +1.700 ASSINANTES</span>\n </div>\n <img class="image" src="asset/icon.png">\n</div>\n<div class="right"></div>\n</div>\n<div id="chat" class="chatbot">\n<div class="cb-header">\n <div id="Voltar" class="cb-getback">\n <img src="asset/rollback.png" alt="">\n </div>\n <div class="cb-photo">\n <img src="https://thispersondoesnotexist.com/image" alt="">\n </div>\n <div class="cb-profile">\n <span id="NameProfile" class="title">Atendente</span>\n <span id="StatusProfile" class="description">online</span>\n </div>\n</div>\n<div class="cb-main">\n <div class="cb-scroll">\n <ol id="ListMsg" class="cb-listmsg">\n\n </ol>\n </div>\n</div>\n<div class="cb-footer">\n <div class="input">\n <span class="sty1"></span>\n <div class="text">\n <input id="InputText" type="text" placeholder="Digite a mensagem">\n </div>\n <span class="sty2"></span>\n </div>\n <div class="button">\n <img id="SendText" src="asset/sender.png" alt="">\n </div>\n</div>\n</div>\n',document.getElementById("SendText").addEventListener("click",()=>{window.userInputText(document.getElementById("InputText")),document.getElementById("InputText").focus()}),document.getElementById("InputText").addEventListener("keydown",e=>{13===e.keyCode&&window.userInputText(e.target),document.getElementById("InputText").focus()}),document.getElementById("BtnCallWhats").addEventListener("click",()=>{document.getElementById("chat").classList.add("show"),document.getElementById("InputText").focus()}),document.getElementById("Voltar").addEventListener("click",()=>{document.getElementById("chat").classList.remove("show")}),document.getElementById("NameProfile").innerText=window.chatname,document.querySelector(".cb-photo").firstElementChild.src=window.chatphoto,new window.Bot;