Implementação parcial do session out

pull/21/head
adriano 2023-01-24 09:30:21 -03:00
parent c334de3cfb
commit 5c44656328
2 changed files with 75 additions and 3 deletions

View File

@ -0,0 +1,62 @@
const fsPromises = require("fs/promises");
const fs = require('fs')
import axios from 'axios';
import * as https from "https";
const sendMessageAPI = async (url: string, body: string) => {
let response: any = null
try {
const httpsAgent = new https.Agent({ rejectUnauthorized: false, });
response = await axios.post(url, {
'x-api-token': 'e23dcfdfeb6be5b91b1bf5c55ee50cc4405f2802',
'x-api-app': 'x-api-app',
}, {
httpsAgent,
headers: { 'Content-Type': 'multipart/form-data' },
});
console.log(`TEST URL CLIENT POST ROUTE: ${url} | STATUS CODE: ${response.status}`);
// if (method == 'get') {
// // const url = 'https://sos.espacolaser.com.br/api/whatsapp/ticket/R32656'
// response = await axios.get(url, {
// httpsAgent,
// headers: {
// 'x-access-token': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOnsiaWQiOjEsInJvbGUiOiJjbGllbnQiLCJob3N0Ijoic29zLmVzcGFjb2xhc2VyLmNvbS5iciIsInRlbmFudCI6ImVzcGFjb2xhc2VyIiwibmFtZSI6IlNFTlNSLklUIiwiY29tcGFueSI6eyJpZCI6NDR9fSwiZGF0ZSI6MTY2MTI2MjY0MywiaWF0IjoxNjYxMjYyNjQzLCJleHAiOjE3NDc2NjI2NDN9.zf91OmRs4_C7B8OlVpLLrQMiRBYc7edP4qAdH_hqxpk',
// 'Origin': 'espacolaser'
// }
// });
// console.log(`TEST URL CLIENT GET ROUTE: ${url} | STATUS CODE: ${response.status}`);
// }
// else if (method == 'post') {
// // const url = 'http://177.107.193.124:8095/labs/zabbix-frontend/api/api.php'
// response = await axios.post(url, {
// 'auth': '0424bd59b807674191e7d77572075f33',
// 'jsonrpc': '2.0',
// 'method': 'chamado.ematendimento',
// 'params[ccusto]': param,
// id: '101'
// }, {
// httpsAgent,
// headers: { 'Content-Type': 'multipart/form-data' },
// });
// console.log(`TEST URL CLIENT POST ROUTE: ${url} | STATUS CODE: ${response.status}`);
// }
} catch (error) {
console.error(`Erro ao consultar endpoint ${url}: ${error}`);
}
return response
}
export default sendMessageAPI;

View File

@ -17,24 +17,34 @@ import { loadContactsCache } from "../../helpers/ContactsCache";
import { loadSchedulesCache } from "../../helpers/SchedulingNotifyCache"; import { loadSchedulesCache } from "../../helpers/SchedulingNotifyCache";
import { createSessionDir } from "../../helpers/CreateSessionDir"; import { createSessionDir } from "../../helpers/CreateSessionDir";
import openSocket from "socket.io-client";
let counter = 0 let counter = 0
export const StartAllWhatsAppsSessions = async (): Promise<void> => { export const StartAllWhatsAppsSessions = async (): Promise<void> => {
console.log('KKKKKKKKKKKKKKKKKKKKKKKK')
const io = require("socket.io-client");
const socket = io("http://localhost:8020/", {
withCredentials: true
});
const cacheLength = await cacheSize() const cacheLength = await cacheSize()
console.log('cacheSize: ', cacheLength) console.log('cacheSize: ', cacheLength)
if (cacheLength == 0) { if (cacheLength == 0) {
console.log('Loading from cache...') console.log('Loading from cache...')
await flushCache() await flushCache()
await loadContactsCache() await loadContactsCache()
await loadTicketsCache() await loadTicketsCache()
} }
await loadSchedulesCache() await loadSchedulesCache()
// await loadWhatsappCache() // await loadWhatsappCache()