Skip to content

Commit

Permalink
Add manual webhook status
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-maj committed Jan 10, 2024
1 parent c29eaed commit 9e81652
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/server/utils/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,55 @@ export const sendWebhookRequest = async (
}
};

interface WebhookData {
queueId: string;
status: WebhooksEventTypes;
}

export const sendWebhooks = async (webhooks: WebhookData[]) => {
const queueIds = webhooks.map((webhook) => webhook.queueId);
const txs = await getTxByIds({ queueIds });
if (!txs || txs.length === 0) {
return;
}

const webhooksWithTxs = webhooks
.map((webhook) => {
const tx = txs.find((tx) => tx.queueId === webhook.queueId);
return {
...webhook,
tx,
};
})
.filter((webhook) => !!webhook.tx);

for (const webhook of webhooksWithTxs) {
const webhookConfigs = await Promise.all([
...((await getWebhook(WebhooksEventTypes.ALL_TX)) || []),
...((await getWebhook(webhook.status)) || []),
]);

await Promise.all(
webhookConfigs.map(async (webhookConfig) => {
if (!webhookConfig.active) {
logger({
service: "server",
level: "debug",
message: "No webhook set or active, skipping webhook send",
});

return;
}

await sendWebhookRequest(
webhookConfig,
webhook.tx as Record<string, any>,
);
}),
);
}
};

export const sendTxWebhook = async (queueIds: string[]): Promise<void> => {
try {
const txDataByIds = await getTxByIds({ queueIds });
Expand Down

0 comments on commit 9e81652

Please sign in to comment.