Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
webhook improvement (#180)
Browse files Browse the repository at this point in the history
* feat: webhook type

* feat: webhook of calls
  • Loading branch information
Useems authored Jul 7, 2022
1 parent 4555971 commit 88179f9
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions src/api/class/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ class WhatsAppInstance {
}
}

async SendWebhook(data) {
async SendWebhook(type, body) {
if (!this.allowWebhook) return
this.axiosInstance.post('', data).catch(() => {})
this.axiosInstance.post('', {
type,
body
}).catch(() => {})
}

async init() {
Expand Down Expand Up @@ -223,7 +226,7 @@ class WhatsAppInstance {
}
}

await this.SendWebhook(webhookData)
await this.SendWebhook('recv_message', webhookData)
})
})

Expand All @@ -235,6 +238,35 @@ class WhatsAppInstance {
// }
//})

sock?.ws.on('CB:call', async (data) => {
if (data.content) {
if (data.content.find(e => e.tag === 'offer')) {
const content = data.content.find(e => e.tag === 'offer')

await this.SendWebhook('call_offer', {
id: content.attrs['call-id'],
timestamp: parseInt(data.attrs.t),
user: {
id: data.attrs.from,
platform: data.attrs.platform,
platform_version: data.attrs.version
}
})
} else if (data.content.find(e => e.tag === 'terminate')) {
const content = data.content.find(e => e.tag === 'terminate')

await this.SendWebhook('call_terminate', {
id: content.attrs['call-id'],
user: {
id: data.attrs.from
},
timestamp: parseInt(data.attrs.t),
reason: data.content[0].attrs.reason
})
}
}
})

sock?.ev.on('groups.upsert', async (newChat) => {
//console.log(newChat)
this.createGroupByApp(newChat)
Expand Down

0 comments on commit 88179f9

Please sign in to comment.