Skip to content

Commit 53050ad

Browse files
author
jrclber
committed
new event call.upsert
1 parent ac374ce commit 53050ad

4 files changed

Lines changed: 38 additions & 22 deletions

File tree

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"multer": "^1.4.5-lts.1",
6666
"node-cache": "^5.1.2",
6767
"npm": "^10.2.4",
68-
"pino-pretty": "^10.2.3",
68+
"pino-pretty": "^11.0.0",
6969
"qrcode": "^1.5.1",
7070
"qrcode-terminal": "^0.12.0",
7171
"redis": "^4.6.11",
@@ -88,10 +88,10 @@
8888
"@types/swagger-ui-express": "^4.1.6",
8989
"@types/uuid": "^9.0.7",
9090
"@types/yamljs": "^0.2.34",
91-
"@typescript-eslint/eslint-plugin": "^6.13.1",
92-
"@typescript-eslint/parser": "^6.13.1",
93-
"copy-webpack-plugin": "^11.0.0",
94-
"eslint": "^8.55.0",
91+
"@typescript-eslint/eslint-plugin": "6.21.0",
92+
"@typescript-eslint/parser": "6.21.0",
93+
"copy-webpack-plugin": "^12.0.2",
94+
"eslint": "8.47.0",
9595
"eslint-config-prettier": "^9.1.0",
9696
"eslint-plugin-prettier": "^5.0.1",
9797
"prettier": "^3.1.0",

src/validate/validate.schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ export const webhookSchema: JSONSchema7 = {
538538
connectionUpdated: { type: 'boolean', enum: [true, false] },
539539
statusInstance: { type: 'boolean', enum: [true, false] },
540540
refreshToken: { type: 'boolean', enum: [true, false] },
541+
callUpsert: { type: 'boolean', enum: [true, false] },
541542
},
542543
},
543544
},

src/whatsapp/dto/webhook.dto.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export class WebhookEvents {
5858
connectionUpdated?: boolean;
5959
statusInstance?: boolean;
6060
refreshToken?: boolean;
61+
callUpsert?: boolean;
6162
}
6263

6364
export type EventsType =
@@ -80,7 +81,8 @@ export type EventsType =
8081
| 'groups.update'
8182
| 'group-participants.update'
8283
| 'status.instance'
83-
| 'refresh.token';
84+
| 'refresh.token'
85+
| 'call.upsert';
8486

8587
export type WebhookEventsType = keyof WebhookEvents;
8688

@@ -104,6 +106,7 @@ export const WebhookEventsEnum: Record<WebhookEventsType, EventsType> = {
104106
connectionUpdated: 'connection.update',
105107
statusInstance: 'status.instance',
106108
refreshToken: 'refresh.token',
109+
callUpsert: 'call.upsert',
107110
};
108111

109112
export type WebhookEventsMap = typeof WebhookEventsEnum;

src/whatsapp/services/whatsapp.service.ts

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import makeWASocket, {
6262
useMultiFileAuthState,
6363
UserFacingSocketConfig,
6464
WABrowserDescription,
65+
WACallEvent,
6566
WAConnectionState,
6667
WAMediaUpload,
6768
WAMessageUpdate,
@@ -971,78 +972,89 @@ export class WAStartupService {
971972
},
972973
};
973974

975+
private readonly callHandler = {
976+
'call.upsert': (call: WACallEvent[]) => {
977+
call.forEach((c) => {
978+
this.sendDataWebhook('callUpsert', c);
979+
});
980+
},
981+
};
982+
974983
private eventHandler() {
975984
this.client.ev.process((events) => {
976985
if (!this.endSession) {
977-
const database = this.configService.get<Database>('DATABASE');
978-
979-
if (events['connection.update']) {
986+
if (events?.['connection.update']) {
980987
this.connectionUpdate(events['connection.update']);
981988
}
982989

983-
if (events['creds.update']) {
990+
if (events?.['creds.update']) {
984991
this.authState.saveCreds();
985992
}
986993

987-
if (events['messaging-history.set']) {
994+
if (events?.['messaging-history.set']) {
988995
const payload = events['messaging-history.set'];
989996
this.messageHandle['messaging-history.set'](payload);
990997
}
991998

992-
if (events['messages.upsert']) {
999+
if (events?.['messages.upsert']) {
9931000
const payload = events['messages.upsert'];
9941001
this.messageHandle['messages.upsert'](payload);
9951002
}
9961003

997-
if (events['messages.update']) {
1004+
if (events?.['messages.update']) {
9981005
const payload = events['messages.update'];
9991006
this.messageHandle['messages.update'](payload);
10001007
}
10011008

1002-
if (events['presence.update']) {
1009+
if (events?.['presence.update']) {
10031010
const payload = events['presence.update'];
10041011
this.sendDataWebhook('presenceUpdated', payload);
10051012
}
10061013

1007-
if (events['groups.upsert']) {
1014+
if (events?.['groups.upsert']) {
10081015
const payload = events['groups.upsert'];
10091016
this.groupHandler['groups.upsert'](payload);
10101017
}
10111018

1012-
if (events['groups.update']) {
1019+
if (events?.['groups.update']) {
10131020
const payload = events['groups.update'];
10141021
this.groupHandler['groups.update'](payload);
10151022
}
10161023

1017-
if (events['group-participants.update']) {
1024+
if (events?.['group-participants.update']) {
10181025
const payload = events['group-participants.update'];
10191026
this.groupHandler['group-participants.update'](payload);
10201027
}
10211028

1022-
if (events['chats.upsert']) {
1029+
if (events?.['chats.upsert']) {
10231030
const payload = events['chats.upsert'];
10241031
this.chatHandle['chats.upsert'](payload);
10251032
}
10261033

1027-
if (events['chats.update']) {
1034+
if (events?.['chats.update']) {
10281035
const payload = events['chats.update'];
10291036
this.chatHandle['chats.update'](payload);
10301037
}
10311038

1032-
if (events['chats.delete']) {
1039+
if (events?.['chats.delete']) {
10331040
const payload = events['chats.delete'];
10341041
this.chatHandle['chats.delete'](payload);
10351042
}
10361043

1037-
if (events['contacts.upsert']) {
1044+
if (events?.['contacts.upsert']) {
10381045
const payload = events['contacts.upsert'];
10391046
this.contactHandle['contacts.upsert'](payload);
10401047
}
10411048

1042-
if (events['contacts.update']) {
1049+
if (events?.['contacts.update']) {
10431050
const payload = events['contacts.update'];
10441051
this.contactHandle['contacts.update'](payload);
10451052
}
1053+
1054+
if (events?.['call']) {
1055+
const payload = events['call'];
1056+
this.callHandler['call.upsert'](payload);
1057+
}
10461058
}
10471059
});
10481060
}

0 commit comments

Comments
 (0)