mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
use old event format for the compatibility with the old webhooks
This commit is contained in:
parent
8d11096142
commit
58708a507e
1 changed files with 22 additions and 7 deletions
|
|
@ -91,17 +91,32 @@ const sendNotification = async (obj: RuleActionObj) => {
|
|||
const sendToWebhook = async (obj: RuleActionObj) => {
|
||||
const [url] = obj.action.params
|
||||
|
||||
let event = obj.ruleEventType.toString()
|
||||
// rename LABEL_CREATED to LABEL_ATTACHED
|
||||
if (obj.ruleEventType === RuleEventType.LabelCreated) {
|
||||
event = 'LABEL_ATTACHED'
|
||||
const [type, action] = obj.ruleEventType.toString().toLowerCase().split('_')
|
||||
|
||||
// use old event format for the compatibility with the old webhooks
|
||||
let event
|
||||
if (type === 'page') {
|
||||
event = obj.data
|
||||
} else if (type === 'label') {
|
||||
event = {
|
||||
labels: obj.data.labels,
|
||||
pageId: obj.data.id,
|
||||
}
|
||||
} else {
|
||||
if (!obj.data.highlights) {
|
||||
return
|
||||
}
|
||||
|
||||
event = {
|
||||
...obj.data.highlights[0],
|
||||
pageId: obj.data.id,
|
||||
}
|
||||
}
|
||||
|
||||
const data = {
|
||||
event,
|
||||
item: obj.data,
|
||||
action,
|
||||
userId: obj.userId,
|
||||
timestamp: Date.now(),
|
||||
[type]: event,
|
||||
}
|
||||
|
||||
logger.info(`triggering webhook: ${url}`)
|
||||
|
|
|
|||
Loading…
Reference in a new issue