1 parent
0a3514d81e
commit
39429a2e44
4 files changed
+17
-4
No files matched your search
@@ -218,11 +218,14 @@ export function populateSessionInfo(
|
||||
) {
|
||||
return (payload: any): WAHAWebhook => {
|
||||
const id = payload._eventId;
|
||||
const timestampMs = payload._timestampMs;
|
||||
const data = { ...payload };
|
||||
delete data._eventId;
|
||||
delete data._timestampMs;
|
||||
const me = session.getSessionMeInfo();
|
||||
return {
|
||||
id: id,
|
||||
timestamp: timestampMs,
|
||||
event: event,
|
||||
session: session.name,
|
||||
metadata: session.sessionConfig?.metadata,
|
||||
|
||||
@@ -178,6 +178,7 @@ export abstract class WhatsappSession {
|
||||
filter(Boolean),
|
||||
map((data) => {
|
||||
data._eventId = generatePrefixedId('evt');
|
||||
data._timestampMs = Date.now();
|
||||
return data;
|
||||
}),
|
||||
retry(),
|
||||
|
||||
@@ -66,7 +66,7 @@ export class WebhookSender {
|
||||
const headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
Object.assign(headers, this.getWebhookHeader());
|
||||
Object.assign(headers, this.getWebhookHeader(json));
|
||||
Object.assign(headers, this.getHMACHeaders(body));
|
||||
const ctx = {
|
||||
id: headers['X-Webhook-Request-Id'],
|
||||
@@ -153,12 +153,13 @@ export class WebhookSender {
|
||||
};
|
||||
}
|
||||
|
||||
protected getWebhookHeader() {
|
||||
protected getWebhookHeader(json: any) {
|
||||
const timestamp = json.timestamp?.toString() || Date.now().toString();
|
||||
return {
|
||||
// UUID, no '-' in it
|
||||
'X-Webhook-Request-Id': ulid(),
|
||||
// unix timestamp with ms
|
||||
'X-Webhook-Timestamp': Date.now().toString(),
|
||||
'X-Webhook-Timestamp': timestamp,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -105,10 +105,18 @@ export class WASessionStatusBody {
|
||||
|
||||
export class WAHAWebhook {
|
||||
@ApiProperty({
|
||||
example: 'evt_01jcn4pjwwg47bwy2gsey6q5sx',
|
||||
example: 'evt_01aaaaaaaaaaaaaaaaaaaaaaaa',
|
||||
description:
|
||||
'Unique identifier for the event - lower case ULID format. https://github.com/ulid/spec',
|
||||
})
|
||||
id: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: 1634567890123,
|
||||
description: 'Unix timestamp (ms) for when the event was created.',
|
||||
})
|
||||
timestamp: number;
|
||||
|
||||
@ApiProperty({
|
||||
example: 'default',
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user