var locationVar = window.document.location; var controller = function () { if (locationVar.protocol == "http:") { // const port = parseInt(locationVar.port) - 1; const port = 9966; const url = locationVar.origin; // return "https://apiv2.bashtechnology.com.br/api"; return url.replace(locationVar.port, port) + "/api"; } else { return "https://apiv2.bashtechnology.com.br/api"; } }; function deslogar() { localStorage.clear(); window.location.replace("/login.html"); } function req(url, type = "POST", data, success, error) { let token = localStorage.getItem("token"); if (token == null && !url.includes("open")) { deslogar(); } let headers = { "Content-Type": "application/json", "Content-Type": "external", App: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbiI6InVuaWZpY2Fkb19mbG93In0.IP3zkbouor29VxS4ytR-UjRiBkB9BMOLXeBnoyBo7Lo", }; if (token != null) { headers.Authorization = token; } $.ajax({ data: data ? JSON.stringify(data) : "", type: type, url: controller() + "/" + url, headers: headers, success: function (res) { success(res); }, error: function (res) { // console.log(res); // if (!res.responseJSON && res.statusText == "error") { // avisos( // "Api Indisponível", // "Entrar em contato com a equipe da Bash.", // "rose-700" // ); // setTimeout(deslogar, 3000); // return; // } res = res.responseJSON; if (res && res.code == 401) { deslogar(); return; } error(res); }, }); } function reqIfError(url, type = "POST", data, success, error) { let token = localStorage.getItem("token"); if (token == null && !url.includes("open")) { deslogar(); } let headers = { "Content-Type": "application/json", "Content-Type": "external", App: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbiI6InVuaWZpY2Fkb19mbG93In0.IP3zkbouor29VxS4ytR-UjRiBkB9BMOLXeBnoyBo7Lo", }; if (token != null) { headers.Authorization = token; } $.ajax({ data: data ? JSON.stringify(data) : "", type: type, url: controller() + "/" + url, headers: headers, success: function (res) { success(res); }, error: function (res) { res = res.responseJSON; if (res && res.code == 401) { deslogar(); return; } error(res); }, }); } function reqWebbot(url, type = "POST", data, success, error) { let headers = { "Content-Type": "application/json", "Content-Type": "external", Authorization: "Token BTNDoz91G0j@kn3Qo43Wym1t4717io0TOY7Mwi_VKReXVtmYvOiy", }; $.ajax({ data: data ? JSON.stringify(data) : "", type: type, url: "https://webbot.bashtechnology.com.br/api" + "/" + url, headers: headers, success: function (res) { success(res); }, error: function (res) { if (!res.responseJSON && res.statusText == "error") { avisos( "Api Indisponível", "Entrar em contato com a equipe da Bash.", "rose-700" ); setTimeout(deslogar, 3000); return; } res = res.responseJSON; if (res && res.status == 401) { deslogar(); return; } error(res); }, }); } function reqAjuda(url, type = "POST", data, success, error, attempts = 3) { let headers = { "Content-Type": "application/json", }; const tryRequest = (remainingAttempts) => { $.ajax({ data: data ? JSON.stringify(data) : "", type: type, url: "https://webbot.bashtechnology.com.br/gpt" + "/" + url, headers: headers, success: function (res) { success(res); }, error: function (res) { if (remainingAttempts > 1) { console.warn( `Tentativa falhou. Restando ${remainingAttempts - 1} tentativas...` ); setTimeout(() => { tryRequest(remainingAttempts - 1); }, 500); return; } if (!res.responseJSON && res.statusText === "error") { avisos( "API Indisponível", "Entrar em contato com a equipe da Bash.", "rose-700" ); return; } res = res.responseJSON; if (res && res.status == 401) { // deslogar(); return; } error(res); }, }); }; tryRequest(attempts); } function reqFlow(url, type = "POST", data, success, error) { let token = localStorage.getItem("token"); if (token == null && !url.includes("open")) { deslogar(); } let headers = { "Content-Type": "application/json", "Content-Type": "external", App: "eyJhbGciOiJIUzI1NiJ9.eyJ0b2tlbiI6ImZsb3dodWJfY2xpZW50ZXMifQ.FJ26VZdFMwxtAWOiRytd4wFg22jn1xqgllsepKB3zc8", }; if (token != null) { headers.Authorization = token; } $.ajax({ data: data ? JSON.stringify(data) : "", type: type, // url: "https://03a2-170-231-215-23.ngrok-free.app" + "/" + url, url: "https://poc-ticket.bashtechnology.com.br" + "/" + url, headers: headers, success: function (res) { success(res); }, error: function (res) { // console.log(res); // if (!res.responseJSON && res.statusText == "error") { // avisos( // "Api Indisponível", // "Entrar em contato com a equipe da Bash.", // "rose-700" // ); // setTimeout(deslogar, 3000); // return; // } res = res.responseJSON; if (res && res.code == 401) { deslogar(); return; } error(res); }, }); }