Added listening_from_me option in Set Typebot

This commit is contained in:
Davidson Gomes 2023-08-23 07:27:40 -03:00
parent b7218a05be
commit 03637b2d4d
16 changed files with 90 additions and 43 deletions

View File

@ -1,3 +1,13 @@
# 1.5.1 (homolog)
### Feature
* Added listening_from_me option in Set Typebot
### Fixed
* Fix looping connection messages in chatwoot
# 1.5.0 (2023-08-18 12:47) # 1.5.0 (2023-08-18 12:47)
### Feature ### Feature

View File

@ -1,6 +1,6 @@
FROM node:16.18-alpine FROM node:16.18-alpine
LABEL version="1.5.0" description="Api to control whatsapp features through http requests." LABEL version="1.5.1" description="Api to control whatsapp features through http requests."
LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes" LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"
LABEL contact="contato@agenciadgcode.com" LABEL contact="contato@agenciadgcode.com"

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{ {
"name": "evolution-api", "name": "evolution-api",
"version": "1.5.0", "version": "1.5.1",
"description": "Rest api for communication with WhatsApp", "description": "Rest api for communication with WhatsApp",
"main": "./dist/src/main.js", "main": "./dist/src/main.js",
"scripts": { "scripts": {

View File

@ -166,17 +166,17 @@ export class ConfigService {
return { return {
SERVER: { SERVER: {
TYPE: process.env.SERVER_TYPE as 'http' | 'https', TYPE: process.env.SERVER_TYPE as 'http' | 'https',
PORT: Number.parseInt(process.env.SERVER_PORT), PORT: Number.parseInt(process.env.SERVER_PORT) || 8080,
URL: process.env.SERVER_URL, URL: process.env.SERVER_URL,
}, },
CORS: { CORS: {
ORIGIN: process.env.CORS_ORIGIN.split(','), ORIGIN: process.env.CORS_ORIGIN.split(',') || ['*'],
METHODS: process.env.CORS_METHODS.split(',') as HttpMethods[], METHODS: (process.env.CORS_METHODS.split(',') as HttpMethods[]) || ['POST', 'GET', 'PUT', 'DELETE'],
CREDENTIALS: process.env?.CORS_CREDENTIALS === 'true', CREDENTIALS: process.env?.CORS_CREDENTIALS === 'true',
}, },
SSL_CONF: { SSL_CONF: {
PRIVKEY: process.env?.SSL_CONF_PRIVKEY, PRIVKEY: process.env?.SSL_CONF_PRIVKEY || '',
FULLCHAIN: process.env?.SSL_CONF_FULLCHAIN, FULLCHAIN: process.env?.SSL_CONF_FULLCHAIN || '',
}, },
STORE: { STORE: {
MESSAGES: process.env?.STORE_MESSAGES === 'true', MESSAGES: process.env?.STORE_MESSAGES === 'true',
@ -195,8 +195,8 @@ export class ConfigService {
}, },
DATABASE: { DATABASE: {
CONNECTION: { CONNECTION: {
URI: process.env.DATABASE_CONNECTION_URI, URI: process.env.DATABASE_CONNECTION_URI || '',
DB_PREFIX_NAME: process.env.DATABASE_CONNECTION_DB_PREFIX_NAME, DB_PREFIX_NAME: process.env.DATABASE_CONNECTION_DB_PREFIX_NAME || 'evolution',
}, },
ENABLED: process.env?.DATABASE_ENABLED === 'true', ENABLED: process.env?.DATABASE_ENABLED === 'true',
SAVE_DATA: { SAVE_DATA: {
@ -209,18 +209,27 @@ export class ConfigService {
}, },
REDIS: { REDIS: {
ENABLED: process.env?.REDIS_ENABLED === 'true', ENABLED: process.env?.REDIS_ENABLED === 'true',
URI: process.env.REDIS_URI, URI: process.env.REDIS_URI || '',
PREFIX_KEY: process.env.REDIS_PREFIX_KEY, PREFIX_KEY: process.env.REDIS_PREFIX_KEY || 'evolution',
}, },
RABBITMQ: { RABBITMQ: {
ENABLED: process.env?.RABBITMQ_ENABLED === 'true', ENABLED: process.env?.RABBITMQ_ENABLED === 'true',
URI: process.env.RABBITMQ_URI, URI: process.env.RABBITMQ_URI || '',
}, },
WEBSOCKET: { WEBSOCKET: {
ENABLED: process.env?.WEBSOCKET_ENABLED === 'true', ENABLED: process.env?.WEBSOCKET_ENABLED === 'true',
}, },
LOG: { LOG: {
LEVEL: process.env?.LOG_LEVEL.split(',') as LogLevel[], LEVEL: (process.env?.LOG_LEVEL.split(',') as LogLevel[]) || [
'ERROR',
'WARN',
'DEBUG',
'INFO',
'LOG',
'VERBOSE',
'DARK',
'WEBHOOKS',
],
COLOR: process.env?.LOG_COLOR === 'true', COLOR: process.env?.LOG_COLOR === 'true',
BAILEYS: (process.env?.LOG_BAILEYS as LogBaileys) || 'error', BAILEYS: (process.env?.LOG_BAILEYS as LogBaileys) || 'error',
}, },
@ -229,7 +238,7 @@ export class ConfigService {
: Number.parseInt(process.env.DEL_INSTANCE) || false, : Number.parseInt(process.env.DEL_INSTANCE) || false,
WEBHOOK: { WEBHOOK: {
GLOBAL: { GLOBAL: {
URL: process.env?.WEBHOOK_GLOBAL_URL, URL: process.env?.WEBHOOK_GLOBAL_URL || '',
ENABLED: process.env?.WEBHOOK_GLOBAL_ENABLED === 'true', ENABLED: process.env?.WEBHOOK_GLOBAL_ENABLED === 'true',
WEBHOOK_BY_EVENTS: process.env?.WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS === 'true', WEBHOOK_BY_EVENTS: process.env?.WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS === 'true',
}, },
@ -266,16 +275,16 @@ export class ConfigService {
COLOR: process.env.QRCODE_COLOR || '#198754', COLOR: process.env.QRCODE_COLOR || '#198754',
}, },
AUTHENTICATION: { AUTHENTICATION: {
TYPE: process.env.AUTHENTICATION_TYPE as 'jwt', TYPE: process.env.AUTHENTICATION_TYPE as 'apikey',
API_KEY: { API_KEY: {
KEY: process.env.AUTHENTICATION_API_KEY, KEY: process.env.AUTHENTICATION_API_KEY || 'BQYHJGJHJ',
}, },
EXPOSE_IN_FETCH_INSTANCES: process.env?.AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES === 'true', EXPOSE_IN_FETCH_INSTANCES: process.env?.AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES === 'true',
JWT: { JWT: {
EXPIRIN_IN: Number.isInteger(process.env?.AUTHENTICATION_JWT_EXPIRIN_IN) EXPIRIN_IN: Number.isInteger(process.env?.AUTHENTICATION_JWT_EXPIRIN_IN)
? Number.parseInt(process.env.AUTHENTICATION_JWT_EXPIRIN_IN) ? Number.parseInt(process.env.AUTHENTICATION_JWT_EXPIRIN_IN)
: 3600, : 3600,
SECRET: process.env.AUTHENTICATION_JWT_SECRET, SECRET: process.env.AUTHENTICATION_JWT_SECRET || 'L=0YWt]b2w[WF>#>:&E`',
}, },
}, },
}; };

View File

@ -985,9 +985,10 @@ export const typebotSchema: JSONSchema7 = {
expire: { type: 'integer' }, expire: { type: 'integer' },
delay_message: { type: 'integer' }, delay_message: { type: 'integer' },
unknown_message: { type: 'string' }, unknown_message: { type: 'string' },
listening_from_me: { type: 'boolean', enum: [true, false] },
}, },
required: ['enabled', 'url', 'typebot', 'expire'], required: ['enabled', 'url', 'typebot', 'expire', 'delay_message', 'unknown_message', 'listening_from_me'],
...isNotEmpty('enabled', 'url', 'typebot', 'expire'), ...isNotEmpty('enabled', 'url', 'typebot', 'expire', 'delay_message', 'unknown_message', 'listening_from_me'),
}; };
export const typebotStatusSchema: JSONSchema7 = { export const typebotStatusSchema: JSONSchema7 = {

View File

@ -67,6 +67,7 @@ export class InstanceController {
typebot_keyword_finish, typebot_keyword_finish,
typebot_delay_message, typebot_delay_message,
typebot_unknown_message, typebot_unknown_message,
typebot_listening_from_me,
}: InstanceDto) { }: InstanceDto) {
try { try {
this.logger.verbose('requested createInstance from ' + instanceName + ' instance'); this.logger.verbose('requested createInstance from ' + instanceName + ' instance');
@ -247,6 +248,7 @@ export class InstanceController {
keyword_finish: typebot_keyword_finish, keyword_finish: typebot_keyword_finish,
delay_message: typebot_delay_message, delay_message: typebot_delay_message,
unknown_message: typebot_unknown_message, unknown_message: typebot_unknown_message,
listening_from_me: typebot_listening_from_me,
}); });
} catch (error) { } catch (error) {
this.logger.log(error); this.logger.log(error);
@ -304,6 +306,7 @@ export class InstanceController {
keyword_finish: typebot_keyword_finish, keyword_finish: typebot_keyword_finish,
delay_message: typebot_delay_message, delay_message: typebot_delay_message,
unknown_message: typebot_unknown_message, unknown_message: typebot_unknown_message,
listening_from_me: typebot_listening_from_me,
}, },
settings, settings,
qrcode: getQrcode, qrcode: getQrcode,
@ -396,6 +399,7 @@ export class InstanceController {
keyword_finish: typebot_keyword_finish, keyword_finish: typebot_keyword_finish,
delay_message: typebot_delay_message, delay_message: typebot_delay_message,
unknown_message: typebot_unknown_message, unknown_message: typebot_unknown_message,
listening_from_me: typebot_listening_from_me,
}, },
settings, settings,
chatwoot: { chatwoot: {

View File

@ -28,6 +28,7 @@ export class InstanceDto {
typebot_keyword_finish?: string; typebot_keyword_finish?: string;
typebot_delay_message?: number; typebot_delay_message?: number;
typebot_unknown_message?: string; typebot_unknown_message?: string;
typebot_listening_from_me?: boolean;
proxy_enabled?: boolean; proxy_enabled?: boolean;
proxy_proxy?: string; proxy_proxy?: string;
} }

View File

@ -14,5 +14,6 @@ export class TypebotDto {
keyword_finish?: string; keyword_finish?: string;
delay_message?: number; delay_message?: number;
unknown_message?: string; unknown_message?: string;
listening_from_me?: boolean;
sessions?: Session[]; sessions?: Session[];
} }

View File

@ -19,6 +19,7 @@ export class TypebotRaw {
keyword_finish?: string; keyword_finish?: string;
delay_message?: number; delay_message?: number;
unknown_message?: string; unknown_message?: string;
listening_from_me?: boolean;
sessions?: Session[]; sessions?: Session[];
} }
@ -31,6 +32,7 @@ const typebotSchema = new Schema<TypebotRaw>({
keyword_finish: { type: String, required: true }, keyword_finish: { type: String, required: true },
delay_message: { type: Number, required: true }, delay_message: { type: Number, required: true },
unknown_message: { type: String, required: true }, unknown_message: { type: String, required: true },
listening_from_me: { type: Boolean, required: true },
sessions: [ sessions: [
{ {
remoteJid: { type: String, required: true }, remoteJid: { type: String, required: true },

View File

@ -151,8 +151,6 @@ export class ChamaaiService {
}, },
}); });
console.log(request.data);
const answer = request.data?.answer; const answer = request.data?.answer;
const type = request.data?.type; const type = request.data?.type;

View File

@ -1444,16 +1444,16 @@ export class ChatwootService {
await this.createBotMessage(instance, msgStatus, 'incoming'); await this.createBotMessage(instance, msgStatus, 'incoming');
} }
if (event === 'connection.update') { // if (event === 'connection.update') {
this.logger.verbose('event connection.update'); // this.logger.verbose('event connection.update');
if (body.status === 'open') { // if (body.status === 'open') {
const msgConnection = `🚀 Connection successfully established!`; // const msgConnection = `🚀 Connection successfully established!`;
this.logger.verbose('send message to chatwoot'); // this.logger.verbose('send message to chatwoot');
await this.createBotMessage(instance, msgConnection, 'incoming'); // await this.createBotMessage(instance, msgConnection, 'incoming');
} // }
} // }
if (event === 'qrcode.updated') { if (event === 'qrcode.updated') {
this.logger.verbose('event qrcode.updated'); this.logger.verbose('event qrcode.updated');

View File

@ -220,6 +220,11 @@ export class WAMonitoringService {
execSync(`rm -rf ${join(STORE_DIR, 'auth', 'apikey', instanceName + '.json')}`); execSync(`rm -rf ${join(STORE_DIR, 'auth', 'apikey', instanceName + '.json')}`);
execSync(`rm -rf ${join(STORE_DIR, 'webhook', instanceName + '.json')}`); execSync(`rm -rf ${join(STORE_DIR, 'webhook', instanceName + '.json')}`);
execSync(`rm -rf ${join(STORE_DIR, 'chatwoot', instanceName + '*')}`); execSync(`rm -rf ${join(STORE_DIR, 'chatwoot', instanceName + '*')}`);
execSync(`rm -rf ${join(STORE_DIR, 'chamaai', instanceName + '*')}`);
execSync(`rm -rf ${join(STORE_DIR, 'proxy', instanceName + '*')}`);
execSync(`rm -rf ${join(STORE_DIR, 'rabbitmq', instanceName + '*')}`);
execSync(`rm -rf ${join(STORE_DIR, 'typebot', instanceName + '*')}`);
execSync(`rm -rf ${join(STORE_DIR, 'websocket', instanceName + '*')}`);
execSync(`rm -rf ${join(STORE_DIR, 'settings', instanceName + '*')}`); execSync(`rm -rf ${join(STORE_DIR, 'settings', instanceName + '*')}`);
return; return;

View File

@ -53,6 +53,7 @@ export class TypebotService {
keyword_finish: findData.keyword_finish, keyword_finish: findData.keyword_finish,
delay_message: findData.delay_message, delay_message: findData.delay_message,
unknown_message: findData.unknown_message, unknown_message: findData.unknown_message,
listening_from_me: findData.listening_from_me,
sessions: findData.sessions, sessions: findData.sessions,
}; };
@ -76,6 +77,7 @@ export class TypebotService {
keyword_finish: findData.keyword_finish, keyword_finish: findData.keyword_finish,
delay_message: findData.delay_message, delay_message: findData.delay_message,
unknown_message: findData.unknown_message, unknown_message: findData.unknown_message,
listening_from_me: findData.listening_from_me,
sessions: findData.sessions, sessions: findData.sessions,
}; };
@ -195,6 +197,7 @@ export class TypebotService {
keyword_finish: data.keyword_finish, keyword_finish: data.keyword_finish,
delay_message: data.delay_message, delay_message: data.delay_message,
unknown_message: data.unknown_message, unknown_message: data.unknown_message,
listening_from_me: data.listening_from_me,
sessions: data.sessions, sessions: data.sessions,
}; };
@ -354,13 +357,15 @@ export class TypebotService {
} }
public async sendTypebot(instance: InstanceDto, remoteJid: string, msg: MessageRaw) { public async sendTypebot(instance: InstanceDto, remoteJid: string, msg: MessageRaw) {
const url = (await this.find(instance)).url; const findTypebot = await this.find(instance);
const typebot = (await this.find(instance)).typebot; const url = findTypebot.url;
const sessions = ((await this.find(instance)).sessions as Session[]) ?? []; const typebot = findTypebot.typebot;
const expire = (await this.find(instance)).expire; const sessions = (findTypebot.sessions as Session[]) ?? [];
const keyword_finish = (await this.find(instance)).keyword_finish; const expire = findTypebot.expire;
const delay_message = (await this.find(instance)).delay_message; const keyword_finish = findTypebot.keyword_finish;
const unknown_message = (await this.find(instance)).unknown_message; const delay_message = findTypebot.delay_message;
const unknown_message = findTypebot.unknown_message;
const listening_from_me = findTypebot.listening_from_me;
const session = sessions.find((session) => session.remoteJid === remoteJid); const session = sessions.find((session) => session.remoteJid === remoteJid);
@ -381,6 +386,7 @@ export class TypebotService {
keyword_finish: keyword_finish, keyword_finish: keyword_finish,
delay_message: delay_message, delay_message: delay_message,
unknown_message: unknown_message, unknown_message: unknown_message,
listening_from_me: listening_from_me,
sessions: sessions, sessions: sessions,
remoteJid: remoteJid, remoteJid: remoteJid,
pushName: msg.pushName, pushName: msg.pushName,
@ -404,6 +410,7 @@ export class TypebotService {
keyword_finish: keyword_finish, keyword_finish: keyword_finish,
delay_message: delay_message, delay_message: delay_message,
unknown_message: unknown_message, unknown_message: unknown_message,
listening_from_me: listening_from_me,
sessions: sessions, sessions: sessions,
remoteJid: remoteJid, remoteJid: remoteJid,
pushName: msg.pushName, pushName: msg.pushName,
@ -428,6 +435,7 @@ export class TypebotService {
keyword_finish: keyword_finish, keyword_finish: keyword_finish,
delay_message: delay_message, delay_message: delay_message,
unknown_message: unknown_message, unknown_message: unknown_message,
listening_from_me: listening_from_me,
sessions, sessions,
}; };
@ -462,6 +470,7 @@ export class TypebotService {
keyword_finish: keyword_finish, keyword_finish: keyword_finish,
delay_message: delay_message, delay_message: delay_message,
unknown_message: unknown_message, unknown_message: unknown_message,
listening_from_me: listening_from_me,
sessions, sessions,
}; };

View File

@ -519,6 +519,9 @@ export class WAStartupService {
this.localTypebot.unknown_message = data?.unknown_message; this.localTypebot.unknown_message = data?.unknown_message;
this.logger.verbose(`Typebot unknown_message: ${this.localTypebot.unknown_message}`); this.logger.verbose(`Typebot unknown_message: ${this.localTypebot.unknown_message}`);
this.localTypebot.listening_from_me = data?.listening_from_me;
this.logger.verbose(`Typebot listening_from_me: ${this.localTypebot.listening_from_me}`);
this.localTypebot.sessions = data?.sessions; this.localTypebot.sessions = data?.sessions;
this.logger.verbose('Typebot loaded'); this.logger.verbose('Typebot loaded');
@ -532,6 +535,7 @@ export class WAStartupService {
this.logger.verbose(`Typebot keyword_finish: ${data.keyword_finish}`); this.logger.verbose(`Typebot keyword_finish: ${data.keyword_finish}`);
this.logger.verbose(`Typebot delay_message: ${data.delay_message}`); this.logger.verbose(`Typebot delay_message: ${data.delay_message}`);
this.logger.verbose(`Typebot unknown_message: ${data.unknown_message}`); this.logger.verbose(`Typebot unknown_message: ${data.unknown_message}`);
this.logger.verbose(`Typebot listening_from_me: ${data.listening_from_me}`);
Object.assign(this.localTypebot, data); Object.assign(this.localTypebot, data);
this.logger.verbose('Typebot set'); this.logger.verbose('Typebot set');
} }
@ -1434,12 +1438,14 @@ export class WAStartupService {
); );
} }
if (this.localTypebot.enabled && messageRaw.key.fromMe === false) { if (this.localTypebot.enabled) {
await this.typebotService.sendTypebot( if (!(this.localTypebot.listening_from_me === false && messageRaw.key.fromMe === true)) {
{ instanceName: this.instance.name }, await this.typebotService.sendTypebot(
messageRaw.key.remoteJid, { instanceName: this.instance.name },
messageRaw, messageRaw.key.remoteJid,
); messageRaw,
);
}
} }
if (this.localChamaai.enabled && messageRaw.key.fromMe === false) { if (this.localChamaai.enabled && messageRaw.key.fromMe === false) {

View File

@ -94,6 +94,7 @@ export declare namespace wa {
keyword_finish?: string; keyword_finish?: string;
delay_message?: number; delay_message?: number;
unknown_message?: string; unknown_message?: string;
listening_from_me?: boolean;
sessions?: Session[]; sessions?: Session[];
}; };