mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-16 04:02:54 -06:00
adjusts in websocket
This commit is contained in:
parent
1172b6c871
commit
04575d8051
@ -53,6 +53,7 @@ RABBITMQ_EXCHANGE_NAME=evolution_exchange
|
|||||||
RABBITMQ_URI=amqp://guest:guest@rabbitmq:5672
|
RABBITMQ_URI=amqp://guest:guest@rabbitmq:5672
|
||||||
|
|
||||||
WEBSOCKET_ENABLED=false
|
WEBSOCKET_ENABLED=false
|
||||||
|
WEBSOCKET_GLOBAL_EVENTS=false
|
||||||
|
|
||||||
WA_BUSINESS_TOKEN_WEBHOOK=evolution
|
WA_BUSINESS_TOKEN_WEBHOOK=evolution
|
||||||
WA_BUSINESS_URL=https://graph.facebook.com
|
WA_BUSINESS_URL=https://graph.facebook.com
|
||||||
|
@ -68,6 +68,7 @@ ENV RABBITMQ_EXCHANGE_NAME=evolution_exchange
|
|||||||
ENV RABBITMQ_URI=amqp://guest:guest@rabbitmq:5672
|
ENV RABBITMQ_URI=amqp://guest:guest@rabbitmq:5672
|
||||||
|
|
||||||
ENV WEBSOCKET_ENABLED=false
|
ENV WEBSOCKET_ENABLED=false
|
||||||
|
ENV WEBSOCKET_GLOBAL_EVENTS=false
|
||||||
|
|
||||||
ENV WA_BUSINESS_TOKEN_WEBHOOK=evolution
|
ENV WA_BUSINESS_TOKEN_WEBHOOK=evolution
|
||||||
ENV WA_BUSINESS_URL=https://graph.facebook.com
|
ENV WA_BUSINESS_URL=https://graph.facebook.com
|
||||||
|
@ -86,6 +86,7 @@ export type Sqs = {
|
|||||||
|
|
||||||
export type Websocket = {
|
export type Websocket = {
|
||||||
ENABLED: boolean;
|
ENABLED: boolean;
|
||||||
|
GLOBAL_EVENTS: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type WaBusiness = {
|
export type WaBusiness = {
|
||||||
@ -299,6 +300,7 @@ export class ConfigService {
|
|||||||
},
|
},
|
||||||
WEBSOCKET: {
|
WEBSOCKET: {
|
||||||
ENABLED: process.env?.WEBSOCKET_ENABLED === 'true',
|
ENABLED: process.env?.WEBSOCKET_ENABLED === 'true',
|
||||||
|
GLOBAL_EVENTS: process.env?.WEBSOCKET_GLOBAL_EVENTS === 'true',
|
||||||
},
|
},
|
||||||
WA_BUSINESS: {
|
WA_BUSINESS: {
|
||||||
TOKEN_WEBHOOK: process.env.WA_BUSINESS_TOKEN_WEBHOOK || '',
|
TOKEN_WEBHOOK: process.env.WA_BUSINESS_TOKEN_WEBHOOK || '',
|
||||||
|
@ -97,6 +97,7 @@ SQS:
|
|||||||
|
|
||||||
WEBSOCKET:
|
WEBSOCKET:
|
||||||
ENABLED: false
|
ENABLED: false
|
||||||
|
GLOBAL_EVENTS: false
|
||||||
|
|
||||||
WA_BUSINESS:
|
WA_BUSINESS:
|
||||||
TOKEN_WEBHOOK: evolution
|
TOKEN_WEBHOOK: evolution
|
||||||
|
@ -828,28 +828,56 @@ export class WAStartupService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.configService.get<Websocket>('WEBSOCKET')?.ENABLED && this.localWebsocket.enabled) {
|
if (this.configService.get<Websocket>('WEBSOCKET')?.ENABLED) {
|
||||||
this.logger.verbose('Sending data to websocket on channel: ' + this.instance.name);
|
this.logger.verbose('Sending data to websocket on channel: ' + this.instance.name);
|
||||||
if (Array.isArray(websocketLocal) && websocketLocal.includes(we)) {
|
const io = getIO();
|
||||||
this.logger.verbose('Sending data to websocket on event: ' + event);
|
|
||||||
const io = getIO();
|
|
||||||
|
|
||||||
const message = {
|
const message = {
|
||||||
event,
|
event,
|
||||||
instance: this.instance.name,
|
instance: this.instance.name,
|
||||||
data,
|
data,
|
||||||
server_url: serverUrl,
|
server_url: serverUrl,
|
||||||
date_time: now,
|
date_time: now,
|
||||||
sender: this.wuid,
|
sender: this.wuid,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (expose && instanceApikey) {
|
if (expose && instanceApikey) {
|
||||||
message['apikey'] = instanceApikey;
|
message['apikey'] = instanceApikey;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.configService.get<Websocket>('WEBSOCKET')?.GLOBAL_EVENTS) {
|
||||||
|
io.emit(event, message);
|
||||||
|
|
||||||
|
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
|
||||||
|
const logData = {
|
||||||
|
local: WAStartupService.name + '.sendData-WebsocketGlobal',
|
||||||
|
event,
|
||||||
|
instance: this.instance.name,
|
||||||
|
data,
|
||||||
|
server_url: serverUrl,
|
||||||
|
apikey: (expose && instanceApikey) || null,
|
||||||
|
date_time: now,
|
||||||
|
sender: this.wuid,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (expose && instanceApikey) {
|
||||||
|
logData['apikey'] = instanceApikey;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.log(logData);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.localWebsocket.enabled && Array.isArray(websocketLocal) && websocketLocal.includes(we)) {
|
||||||
|
this.logger.verbose('Sending data to websocket on event: ' + event);
|
||||||
|
|
||||||
this.logger.verbose('Sending data to socket.io in channel: ' + this.instance.name);
|
this.logger.verbose('Sending data to socket.io in channel: ' + this.instance.name);
|
||||||
io.of(`/${this.instance.name}`).emit(event, message);
|
io.of(`/${this.instance.name}`).emit(event, message);
|
||||||
|
|
||||||
|
if (this.configService.get<Websocket>('WEBSOCKET')?.GLOBAL_EVENTS) {
|
||||||
|
io.emit(event, message);
|
||||||
|
}
|
||||||
|
|
||||||
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
|
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
|
||||||
const logData = {
|
const logData = {
|
||||||
local: WAStartupService.name + '.sendData-Websocket',
|
local: WAStartupService.name + '.sendData-Websocket',
|
||||||
|
Loading…
Reference in New Issue
Block a user