mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 01:41:24 -06:00
Merge branch 'release/1.4.3'
This commit is contained in:
commit
82b1567ae5
@ -1,3 +1,11 @@
|
||||
# 1.4.3 (2023-07-25 10:51)
|
||||
|
||||
### Fixed
|
||||
|
||||
* Adjusts in settings with options always_online, read_messages and read_status
|
||||
* Fixed send webhook for event CALL
|
||||
* Create instance with settings
|
||||
|
||||
# 1.4.2 (2023-07-24 20:52)
|
||||
|
||||
### Fixed
|
||||
|
@ -73,6 +73,7 @@ WEBHOOK_EVENTS_GROUPS_UPSERT=true
|
||||
WEBHOOK_EVENTS_GROUPS_UPDATE=true
|
||||
WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE=true
|
||||
WEBHOOK_EVENTS_CONNECTION_UPDATE=true
|
||||
WEBHOOK_EVENTS_CALL=true
|
||||
# This event fires every time a new token is requested via the refresh route
|
||||
WEBHOOK_EVENTS_NEW_JWT_TOKEN=false
|
||||
|
||||
|
@ -74,6 +74,7 @@ ENV WEBHOOK_EVENTS_GROUPS_UPSERT=true
|
||||
ENV WEBHOOK_EVENTS_GROUPS_UPDATE=true
|
||||
ENV WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE=true
|
||||
ENV WEBHOOK_EVENTS_CONNECTION_UPDATE=true
|
||||
ENV WEBHOOK_EVENTS_CALL=true
|
||||
|
||||
ENV WEBHOOK_EVENTS_NEW_JWT_TOKEN=false
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "evolution-api",
|
||||
"version": "1.4.2",
|
||||
"version": "1.4.3",
|
||||
"description": "Rest api for communication with WhatsApp",
|
||||
"main": "./dist/src/main.js",
|
||||
"scripts": {
|
||||
|
@ -89,6 +89,7 @@ export type EventsWebhook = {
|
||||
GROUPS_UPSERT: boolean;
|
||||
GROUP_UPDATE: boolean;
|
||||
GROUP_PARTICIPANTS_UPDATE: boolean;
|
||||
CALL: boolean;
|
||||
NEW_JWT_TOKEN: boolean;
|
||||
};
|
||||
|
||||
@ -245,6 +246,7 @@ export class ConfigService {
|
||||
GROUP_UPDATE: process.env?.WEBHOOK_EVENTS_GROUPS_UPDATE === 'true',
|
||||
GROUP_PARTICIPANTS_UPDATE:
|
||||
process.env?.WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE === 'true',
|
||||
CALL: process.env?.WEBHOOK_EVENTS_CALL === 'true',
|
||||
NEW_JWT_TOKEN: process.env?.WEBHOOK_EVENTS_NEW_JWT_TOKEN === 'true',
|
||||
},
|
||||
},
|
||||
|
@ -110,6 +110,7 @@ WEBHOOK:
|
||||
GROUP_UPDATE: true
|
||||
GROUP_PARTICIPANTS_UPDATE: true
|
||||
CONNECTION_UPDATE: true
|
||||
CALL: true
|
||||
# This event fires every time a new token is requested via the refresh route
|
||||
NEW_JWT_TOKEN: false
|
||||
|
||||
|
@ -53,6 +53,7 @@ export const instanceNameSchema: JSONSchema7 = {
|
||||
'GROUP_UPDATE',
|
||||
'GROUP_PARTICIPANTS_UPDATE',
|
||||
'CONNECTION_UPDATE',
|
||||
'CALL',
|
||||
'NEW_JWT_TOKEN',
|
||||
],
|
||||
},
|
||||
@ -455,7 +456,7 @@ export const readMessageSchema: JSONSchema7 = {
|
||||
$id: v4(),
|
||||
type: 'object',
|
||||
properties: {
|
||||
readMessages: {
|
||||
read_messages: {
|
||||
type: 'array',
|
||||
minItems: 1,
|
||||
uniqueItems: true,
|
||||
@ -470,7 +471,7 @@ export const readMessageSchema: JSONSchema7 = {
|
||||
},
|
||||
},
|
||||
},
|
||||
required: ['readMessages'],
|
||||
required: ['read_messages'],
|
||||
};
|
||||
|
||||
export const privacySettingsSchema: JSONSchema7 = {
|
||||
@ -854,6 +855,7 @@ export const webhookSchema: JSONSchema7 = {
|
||||
'GROUP_UPDATE',
|
||||
'GROUP_PARTICIPANTS_UPDATE',
|
||||
'CONNECTION_UPDATE',
|
||||
'CALL',
|
||||
'NEW_JWT_TOKEN',
|
||||
],
|
||||
},
|
||||
@ -884,7 +886,22 @@ export const settingsSchema: JSONSchema7 = {
|
||||
reject_call: { type: 'boolean', enum: [true, false] },
|
||||
msg_call: { type: 'string' },
|
||||
groups_ignore: { type: 'boolean', enum: [true, false] },
|
||||
always_online: { type: 'boolean', enum: [true, false] },
|
||||
read_messages: { type: 'boolean', enum: [true, false] },
|
||||
read_status: { type: 'boolean', enum: [true, false] },
|
||||
},
|
||||
required: ['reject_call'],
|
||||
...isNotEmpty('reject_call'),
|
||||
required: [
|
||||
'reject_call',
|
||||
'groups_ignore',
|
||||
'always_online',
|
||||
'read_messages',
|
||||
'read_status',
|
||||
],
|
||||
...isNotEmpty(
|
||||
'reject_call',
|
||||
'groups_ignore',
|
||||
'always_online',
|
||||
'read_messages',
|
||||
'read_status',
|
||||
),
|
||||
};
|
||||
|
@ -13,6 +13,7 @@ import { Logger } from '../../config/logger.config';
|
||||
import { wa } from '../types/wa.types';
|
||||
import { RedisCache } from '../../db/redis.client';
|
||||
import { isURL } from 'class-validator';
|
||||
import { SettingsService } from '../services/settings.service';
|
||||
|
||||
export class InstanceController {
|
||||
constructor(
|
||||
@ -23,6 +24,7 @@ export class InstanceController {
|
||||
private readonly authService: AuthService,
|
||||
private readonly webhookService: WebhookService,
|
||||
private readonly chatwootService: ChatwootService,
|
||||
private readonly settingsService: SettingsService,
|
||||
private readonly cache: RedisCache,
|
||||
) {}
|
||||
|
||||
@ -40,6 +42,12 @@ export class InstanceController {
|
||||
chatwoot_token,
|
||||
chatwoot_url,
|
||||
chatwoot_sign_msg,
|
||||
reject_call,
|
||||
msg_call,
|
||||
groups_ignore,
|
||||
always_online,
|
||||
read_messages,
|
||||
read_status,
|
||||
}: InstanceDto) {
|
||||
try {
|
||||
this.logger.verbose('requested createInstance from ' + instanceName + ' instance');
|
||||
@ -102,6 +110,20 @@ export class InstanceController {
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.verbose('creating settings');
|
||||
const settings: wa.LocalSettings = {
|
||||
reject_call: reject_call || false,
|
||||
msg_call: msg_call || '',
|
||||
groups_ignore: groups_ignore || false,
|
||||
always_online: always_online || false,
|
||||
read_messages: read_messages || false,
|
||||
read_status: read_status || false,
|
||||
};
|
||||
|
||||
this.logger.verbose('settings: ' + JSON.stringify(settings));
|
||||
|
||||
this.settingsService.create(instance, settings);
|
||||
|
||||
if (!chatwoot_account_id || !chatwoot_token || !chatwoot_url) {
|
||||
let getQrcode: wa.QrCode;
|
||||
|
||||
@ -121,6 +143,7 @@ export class InstanceController {
|
||||
webhook,
|
||||
webhook_by_events,
|
||||
events: getEvents,
|
||||
settings,
|
||||
qrcode: getQrcode,
|
||||
};
|
||||
|
||||
@ -179,6 +202,7 @@ export class InstanceController {
|
||||
webhook,
|
||||
webhook_by_events,
|
||||
events: getEvents,
|
||||
settings,
|
||||
chatwoot: {
|
||||
enabled: true,
|
||||
account_id: chatwoot_account_id,
|
||||
|
@ -59,7 +59,7 @@ class Key {
|
||||
remoteJid: string;
|
||||
}
|
||||
export class ReadMessageDto {
|
||||
readMessages: Key[];
|
||||
read_messages: Key[];
|
||||
}
|
||||
|
||||
class LastMessage {
|
||||
|
@ -1,11 +1,17 @@
|
||||
export class InstanceDto {
|
||||
instanceName: string;
|
||||
webhook?: string;
|
||||
webhook_by_events?: boolean;
|
||||
events?: string[];
|
||||
qrcode?: boolean;
|
||||
number?: string;
|
||||
token?: string;
|
||||
webhook?: string;
|
||||
webhook_by_events?: boolean;
|
||||
events?: string[];
|
||||
reject_call?: boolean;
|
||||
msg_call?: string;
|
||||
groups_ignore?: boolean;
|
||||
always_online?: boolean;
|
||||
read_messages?: boolean;
|
||||
read_status?: boolean;
|
||||
chatwoot_account_id?: string;
|
||||
chatwoot_token?: string;
|
||||
chatwoot_url?: string;
|
||||
|
@ -2,4 +2,7 @@ export class SettingsDto {
|
||||
reject_call?: boolean;
|
||||
msg_call?: string;
|
||||
groups_ignore?: boolean;
|
||||
always_online?: boolean;
|
||||
read_messages?: boolean;
|
||||
read_status?: boolean;
|
||||
}
|
||||
|
@ -6,6 +6,9 @@ export class SettingsRaw {
|
||||
reject_call?: boolean;
|
||||
msg_call?: string;
|
||||
groups_ignore?: boolean;
|
||||
always_online?: boolean;
|
||||
read_messages?: boolean;
|
||||
read_status?: boolean;
|
||||
}
|
||||
|
||||
const settingsSchema = new Schema<SettingsRaw>({
|
||||
@ -13,6 +16,9 @@ const settingsSchema = new Schema<SettingsRaw>({
|
||||
reject_call: { type: Boolean, required: true },
|
||||
msg_call: { type: String, required: true },
|
||||
groups_ignore: { type: Boolean, required: true },
|
||||
always_online: { type: Boolean, required: true },
|
||||
read_messages: { type: Boolean, required: true },
|
||||
read_status: { type: Boolean, required: true },
|
||||
});
|
||||
|
||||
export const SettingsModel = dbserver?.model(
|
||||
|
@ -362,6 +362,15 @@ export class WAStartupService {
|
||||
this.localSettings.groups_ignore = data?.groups_ignore;
|
||||
this.logger.verbose(`Settings groups_ignore: ${this.localSettings.groups_ignore}`);
|
||||
|
||||
this.localSettings.always_online = data?.always_online;
|
||||
this.logger.verbose(`Settings always_online: ${this.localSettings.always_online}`);
|
||||
|
||||
this.localSettings.read_messages = data?.read_messages;
|
||||
this.logger.verbose(`Settings read_messages: ${this.localSettings.read_messages}`);
|
||||
|
||||
this.localSettings.read_status = data?.read_status;
|
||||
this.logger.verbose(`Settings read_status: ${this.localSettings.read_status}`);
|
||||
|
||||
this.logger.verbose('Settings loaded');
|
||||
}
|
||||
|
||||
@ -371,8 +380,13 @@ export class WAStartupService {
|
||||
this.logger.verbose(`Settings reject_call: ${data.reject_call}`);
|
||||
this.logger.verbose(`Settings msg_call: ${data.msg_call}`);
|
||||
this.logger.verbose(`Settings groups_ignore: ${data.groups_ignore}`);
|
||||
this.logger.verbose(`Settings always_online: ${data.always_online}`);
|
||||
this.logger.verbose(`Settings read_messages: ${data.read_messages}`);
|
||||
this.logger.verbose(`Settings read_status: ${data.read_status}`);
|
||||
Object.assign(this.localSettings, data);
|
||||
this.logger.verbose('Settings set');
|
||||
|
||||
this.client?.ws?.close();
|
||||
}
|
||||
|
||||
public async findSettings() {
|
||||
@ -387,6 +401,9 @@ export class WAStartupService {
|
||||
this.logger.verbose(`Settings url: ${data.reject_call}`);
|
||||
this.logger.verbose(`Settings msg_call: ${data.msg_call}`);
|
||||
this.logger.verbose(`Settings groups_ignore: ${data.groups_ignore}`);
|
||||
this.logger.verbose(`Settings always_online: ${data.always_online}`);
|
||||
this.logger.verbose(`Settings read_messages: ${data.read_messages}`);
|
||||
this.logger.verbose(`Settings read_status: ${data.read_status}`);
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -847,6 +864,7 @@ export class WAStartupService {
|
||||
printQRInTerminal: false,
|
||||
browser,
|
||||
version,
|
||||
markOnlineOnConnect: this.localSettings.always_online,
|
||||
connectTimeoutMs: 60_000,
|
||||
qrTimeout: 40_000,
|
||||
defaultQueryTimeoutMs: undefined,
|
||||
@ -1143,6 +1161,14 @@ export class WAStartupService {
|
||||
source: getDevice(received.key.id),
|
||||
};
|
||||
|
||||
if (this.localSettings.read_messages && received.key.id !== 'status@broadcast') {
|
||||
await this.client.readMessages([received.key]);
|
||||
}
|
||||
|
||||
if (this.localSettings.read_status && received.key.id === 'status@broadcast') {
|
||||
await this.client.readMessages([received.key]);
|
||||
}
|
||||
|
||||
this.logger.log(messageRaw);
|
||||
|
||||
this.logger.verbose('Sending data to webhook in event MESSAGES_UPSERT');
|
||||
@ -1362,11 +1388,15 @@ export class WAStartupService {
|
||||
text: settings.msg_call,
|
||||
});
|
||||
|
||||
this.logger.verbose('Sending data to event messages.upsert');
|
||||
this.client.ev.emit('messages.upsert', {
|
||||
messages: [msg],
|
||||
type: 'notify',
|
||||
});
|
||||
}
|
||||
|
||||
this.logger.verbose('Sending data to webhook in event CALL');
|
||||
this.sendDataWebhook(Events.CALL, call);
|
||||
}
|
||||
|
||||
if (events['connection.update']) {
|
||||
@ -2400,7 +2430,7 @@ export class WAStartupService {
|
||||
this.logger.verbose('Marking message as read');
|
||||
try {
|
||||
const keys: proto.IMessageKey[] = [];
|
||||
data.readMessages.forEach((read) => {
|
||||
data.read_messages.forEach((read) => {
|
||||
if (isJidGroup(read.remoteJid) || isJidUser(read.remoteJid)) {
|
||||
keys.push({
|
||||
remoteJid: read.remoteJid,
|
||||
@ -2640,7 +2670,6 @@ export class WAStartupService {
|
||||
await this.client.updateGroupsAddPrivacy(settings.privacySettings.groupadd);
|
||||
this.logger.verbose('Groups add privacy updated');
|
||||
|
||||
// reinicia a instancia
|
||||
this.client?.ws?.close();
|
||||
|
||||
return {
|
||||
|
@ -22,6 +22,7 @@ export enum Events {
|
||||
GROUPS_UPSERT = 'groups.upsert',
|
||||
GROUPS_UPDATE = 'groups.update',
|
||||
GROUP_PARTICIPANTS_UPDATE = 'group-participants.update',
|
||||
CALL = 'call',
|
||||
}
|
||||
|
||||
export declare namespace wa {
|
||||
@ -61,6 +62,9 @@ export declare namespace wa {
|
||||
reject_call?: boolean;
|
||||
msg_call?: string;
|
||||
groups_ignore?: boolean;
|
||||
always_online?: boolean;
|
||||
read_messages?: boolean;
|
||||
read_status?: boolean;
|
||||
};
|
||||
|
||||
export type StateConnection = {
|
||||
|
@ -94,6 +94,7 @@ export const instanceController = new InstanceController(
|
||||
authService,
|
||||
webhookService,
|
||||
chatwootService,
|
||||
settingsService,
|
||||
cache,
|
||||
);
|
||||
export const viewsController = new ViewsController(waMonitor, configService);
|
||||
|
Loading…
Reference in New Issue
Block a user