Skip to content

Commit

Permalink
reference of the instance in the webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
jrCleber committed Jan 2, 2024
1 parent e5acc24 commit 5e9f180
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
4 changes: 0 additions & 4 deletions apiary.apib

This file was deleted.

21 changes: 14 additions & 7 deletions src/whatsapp/services/whatsapp.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,19 +250,27 @@ export class WAStartupService {

private async sendDataWebhook<T = any>(event: WebhookEventsType, data: T) {
const eventDesc = WebhookEventsEnum[event];
console.log(1, eventDesc);

try {
if (this.webhook?.enabled && isURL(this.webhook?.url)) {
if (this.webhook?.events && this.webhook?.events[event]) {
await axios.post(
this.webhook.url,
{ event: eventDesc, data },
{
event: eventDesc,
instance: this.instance,
data,
},
{ headers: { 'Resource-Owner': this.instance.ownerJid } },
);
} else {
await axios.post(
this.webhook.url,
{ event: eventDesc, data },
{
event: eventDesc,
instance: this.instance,
data,
},
{ headers: { 'Resource-Owner': this.instance.ownerJid } },
);
}
Expand Down Expand Up @@ -294,7 +302,7 @@ export class WAStartupService {
globalWebhook.URL,
{
event: eventDesc,
instance: this.instance.name,
instance: this.instance,
data,
},
{ headers: { 'Resource-owner': this.instance.ownerJid } },
Expand Down Expand Up @@ -413,14 +421,15 @@ export class WAStartupService {
this.instance.profilePicUrl = (
await this.profilePicture(this.instance.ownerJid)
).profilePictureUrl;
this.instance.connectionStatus = 'ONLINE';

this.repository.instance
.update({
where: { id: this.instance.id },
data: {
ownerJid: this.instance.ownerJid,
profilePicUrl: this.instance.profilePicUrl,
connectionStatus: 'ONLINE',
connectionStatus: this.instance.connectionStatus,
},
})
.catch((err) => this.logger.error(err));
Expand Down Expand Up @@ -1322,8 +1331,6 @@ export class WAStartupService {
public async mediaMessage(data: SendMediaDto) {
const generate = await this.prepareMediaMessage(data.mediaMessage);

console.log(generate);

return await this.sendMessageWithTyping(
data.number,
{ ...generate.message },
Expand Down

0 comments on commit 5e9f180

Please sign in to comment.