Skip to content

Commit f51c3b6

Browse files
committed
feat: Added audio to mp4 converter in optionally get Base64 From MediaMessage
1 parent 870968a commit f51c3b6

File tree

12 files changed

+132
-39
lines changed

12 files changed

+132
-39
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# 1.1.3 (homolog)
22

3+
### Features
4+
5+
* Added configuration for Baileys log level in env
6+
* Added audio to mp4 converter in optionally get Base64 From MediaMessage
7+
38
### Fixed
49

510
* Added timestamp internally in urls to avoid caching
@@ -8,6 +13,7 @@
813
* Fixed cash when sending stickers via url
914
* Improved how Redis works for instances
1015
* Fixed problem when disconnecting the instance it removes the instance
16+
* Fixed problem sending ack when preview is done by me
1117

1218
# 1.1.2 (2023-06-28 13:43)
1319

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ENV CORS_ORIGIN="*"
1616
ENV CORS_METHODS="POST,GET,PUT,DELETE"
1717
ENV CORS_CREDENTIALS=true
1818

19-
ENV LOG_LEVEL="ERROR,WARN,DEBUG,INFO,LOG,VERBOSE,DARK"
19+
ENV LOG_LEVEL=$LOG_LEVEL
2020
ENV LOG_COLOR=true
2121

2222
ENV DEL_INSTANCE=$DEL_INSTANCE

docker-compose.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ services:
1414
- evolution_instances:/evolution/instances
1515
- evolution_store:/evolution/store
1616
environment:
17+
- LOG_LEVEL=ERROR,WARN,DEBUG,INFO,LOG,VERBOSE,DARK,WEBHOOKS
18+
- LOG_BAILEYS=error
1719
# Determine how long the instance should be deleted from memory in case of no connection.
1820
# Default time: 5 minutes
1921
# If you don't even want an expiration, enter the value false
20-
- DEL_INSTANCE=5 # or false
22+
- DEL_INSTANCE=false # 5 or false
2123
# Temporary data storage
2224
- STORE_MESSAGES=true
2325
- STORE_MESSAGE_UP=true

src/config/env.config.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,22 @@ export type Cors = {
1313
CREDENTIALS: boolean;
1414
};
1515

16-
export type LogLevel = 'ERROR' | 'WARN' | 'DEBUG' | 'INFO' | 'LOG' | 'VERBOSE' | 'DARK';
16+
export type LogBaileys = 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
17+
18+
export type LogLevel =
19+
| 'ERROR'
20+
| 'WARN'
21+
| 'DEBUG'
22+
| 'INFO'
23+
| 'LOG'
24+
| 'VERBOSE'
25+
| 'DARK'
26+
| 'WEBHOOKS';
27+
1728
export type Log = {
1829
LEVEL: LogLevel[];
1930
COLOR: boolean;
31+
BAILEYS: LogBaileys;
2032
};
2133

2234
export type SaveData = {
@@ -204,6 +216,7 @@ export class ConfigService {
204216
LOG: {
205217
LEVEL: process.env?.LOG_LEVEL.split(',') as LogLevel[],
206218
COLOR: process.env?.LOG_COLOR === 'true',
219+
BAILEYS: (process.env?.LOG_BAILEYS as LogBaileys) || 'error',
207220
},
208221
DEL_INSTANCE: isBooleanString(process.env?.DEL_INSTANCE)
209222
? process.env.DEL_INSTANCE === 'true'

src/dev-env.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ LOG:
3636
- LOG
3737
- VERBOSE
3838
- DARK
39+
- WEBHOOKS
3940
COLOR: true
41+
BAILEYS: error # "fatal" | "error" | "warn" | "info" | "debug" | "trace"
4042

4143
# Determine how long the instance should be deleted from memory in case of no connection.
4244
# Default time: 5 minutes
4345
# If you don't even want an expiration, enter the value false
44-
DEL_INSTANCE: 5 # or false
46+
DEL_INSTANCE: false # or false
4547

4648
# Temporary data storage
4749
STORE:

src/whatsapp/controllers/chat.controller.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ProfileStatusDto,
1010
ReadMessageDto,
1111
WhatsAppNumberDto,
12+
getBase64FromMediaMessageDto,
1213
} from '../dto/chat.dto';
1314
import { InstanceDto } from '../dto/instance.dto';
1415
import { ContactQuery } from '../repository/contact.repository';
@@ -45,11 +46,9 @@ export class ChatController {
4546

4647
public async getBase64FromMediaMessage(
4748
{ instanceName }: InstanceDto,
48-
message: proto.IWebMessageInfo,
49+
data: getBase64FromMediaMessageDto,
4950
) {
50-
return await this.waMonitor.waInstances[instanceName].getBase64FromMediaMessage(
51-
message,
52-
);
51+
return await this.waMonitor.waInstances[instanceName].getBase64FromMediaMessage(data);
5352
}
5453

5554
public async fetchMessages({ instanceName }: InstanceDto, query: MessageQuery) {

src/whatsapp/controllers/instance.controller.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ export class InstanceController {
207207
);
208208

209209
this.waMonitor.waInstances[instanceName]?.client?.ws?.close();
210-
this.waMonitor.waInstances[instanceName]?.client?.end(undefined);
211210

212211
return { error: false, message: 'Instance logged out' };
213212
} catch (error) {

src/whatsapp/dto/chat.dto.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
WAPrivacyOnlineValue,
33
WAPrivacyValue,
44
WAReadReceiptsValue,
5+
proto,
56
} from '@whiskeysockets/baileys';
67

78
export class OnWhatsAppDto {
@@ -12,6 +13,11 @@ export class OnWhatsAppDto {
1213
) {}
1314
}
1415

16+
export class getBase64FromMediaMessageDto {
17+
message: proto.WebMessageInfo;
18+
convertToMp4?: boolean;
19+
}
20+
1521
export class WhatsAppNumberDto {
1622
numbers: string[];
1723
}

src/whatsapp/routers/chat.router.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
ProfileStatusDto,
2323
ReadMessageDto,
2424
WhatsAppNumberDto,
25+
getBase64FromMediaMessageDto,
2526
} from '../dto/chat.dto';
2627
import { ContactQuery } from '../repository/contact.repository';
2728
import { MessageQuery } from '../repository/message.repository';
@@ -101,10 +102,10 @@ export class ChatRouter extends RouterBroker {
101102
return res.status(HttpStatus.OK).json(response);
102103
})
103104
.post(this.routerPath('getBase64FromMediaMessage'), ...guards, async (req, res) => {
104-
const response = await this.dataValidate<proto.IWebMessageInfo>({
105+
const response = await this.dataValidate<getBase64FromMediaMessageDto>({
105106
request: req,
106107
schema: null,
107-
ClassRef: Object,
108+
ClassRef: getBase64FromMediaMessageDto,
108109
execute: (instance, data) =>
109110
chatController.getBase64FromMediaMessage(instance, data),
110111
});

src/whatsapp/services/monitor.service.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ export class WAMonitoringService {
253253
this.logger.warn(`Instance "${instanceName}" - REMOVED`);
254254
}
255255
});
256+
this.eventEmitter.on('logout.instance', async (instanceName: string) => {
257+
try {
258+
this.cleaningUp(instanceName);
259+
} finally {
260+
this.logger.warn(`Instance "${instanceName}" - LOGOUT`);
261+
}
262+
});
256263
}
257264

258265
private noConnection() {

0 commit comments

Comments
 (0)