From 5c446563286c1cbd3a46815e7a7bd114cf35dec9 Mon Sep 17 00:00:00 2001 From: adriano Date: Tue, 24 Jan 2023 09:30:21 -0300 Subject: [PATCH] =?UTF-8?q?Implementa=C3=A7=C3=A3o=20parcial=20do=20sessio?= =?UTF-8?q?n=20out?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/helpers/SendMessageOnAPIQueue.ts | 62 +++++++++++++++++++ .../WbotServices/StartAllWhatsAppsSessions.ts | 16 ++++- 2 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 backend/src/helpers/SendMessageOnAPIQueue.ts diff --git a/backend/src/helpers/SendMessageOnAPIQueue.ts b/backend/src/helpers/SendMessageOnAPIQueue.ts new file mode 100644 index 0000000..7c4eba8 --- /dev/null +++ b/backend/src/helpers/SendMessageOnAPIQueue.ts @@ -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; \ No newline at end of file diff --git a/backend/src/services/WbotServices/StartAllWhatsAppsSessions.ts b/backend/src/services/WbotServices/StartAllWhatsAppsSessions.ts index 8a57695..a3bccef 100644 --- a/backend/src/services/WbotServices/StartAllWhatsAppsSessions.ts +++ b/backend/src/services/WbotServices/StartAllWhatsAppsSessions.ts @@ -17,24 +17,34 @@ import { loadContactsCache } from "../../helpers/ContactsCache"; import { loadSchedulesCache } from "../../helpers/SchedulingNotifyCache"; import { createSessionDir } from "../../helpers/CreateSessionDir"; +import openSocket from "socket.io-client"; + let counter = 0 export const StartAllWhatsAppsSessions = async (): Promise => { + + + console.log('KKKKKKKKKKKKKKKKKKKKKKKK') + + const io = require("socket.io-client"); + const socket = io("http://localhost:8020/", { + withCredentials: true + }); + + const cacheLength = await cacheSize() console.log('cacheSize: ', cacheLength) - - if (cacheLength == 0) { console.log('Loading from cache...') await flushCache() await loadContactsCache() await loadTicketsCache() } - + await loadSchedulesCache() // await loadWhatsappCache()