Skip to content

Commit

Permalink
[core] Add me and version to webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
allburov committed Oct 12, 2023
1 parent b327212 commit c46bc1b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
9 changes: 8 additions & 1 deletion docs/site/content/en/docs/how-to/webhooks/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,15 @@ On the URL that you set you'll receive **HTTP POST** request with a JSON string
"event": "message",
"session": "default",
"engine": "WEBJS",
"environment": {
"tier": "PLUS",
"version": "2023.10.12"
},
"me": {
"id": "[email protected]",
"pushName": "~"
},
"payload": {
...
}
}
```
Expand Down
2 changes: 2 additions & 0 deletions docs/site/content/en/docs/overview/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ You even can **subscribe to get new updates** there!
## 2023.10
October 2023
- Add `message.revoked` event in **WEBJS** engine
- Add `me` field in webhook payload - now you can know which number is associated with the session
- Add `enviroment` field in webhook payload - now you can know which environment is used for the session

## 2023.9
September 2023
Expand Down
6 changes: 5 additions & 1 deletion src/core/webhooks.core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { WebhookConductor, WebhookSender } from './abc/webhooks.abc';
import { NotImplementedByEngineError } from './exceptions';
import request = require('request');
import { WAHAWebhook } from '../structures/webhooks.dto';
import { VERSION } from '../version';

export class WebhookSenderCore extends WebhookSender {
send(json) {
Expand Down Expand Up @@ -90,17 +91,20 @@ export class WebhookConductorCore implements WebhookConductor {
this.log.log(`Webhooks were configured for ${url}.`);
}

public callWebhook(
public async callWebhook(
event,
session: WhatsappSession,
data: any,
sender: WebhookSender,
) {
const me = await session.getSessionMeInfo().catch((err) => null);
const json: WAHAWebhook = {
event: event,
session: session.name,
me: me,
payload: data,
engine: session.engine,
environment: VERSION,
};
sender.send(json);
}
Expand Down
6 changes: 6 additions & 0 deletions src/structures/webhooks.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { WAMessage } from './responses.dto';
import { MessageDestination } from './chatting.dto';
import { ChatIdProperty, MessageIdProperty } from './properties.dto';
import { WAHAChatPresences } from './presence.dto';
import { MeInfo } from './sessions.dto';

export class WAMessageAckBody {
@MessageIdProperty()
Expand Down Expand Up @@ -87,6 +88,11 @@ export class WAHAWebhook {
})
engine: WAHAEngine;

me: MeInfo | null;

// eslint-disable-next-line @typescript-eslint/ban-types
environment: object;

event: WAHAEvents;

payload:
Expand Down

0 comments on commit c46bc1b

Please sign in to comment.