Add support for Self-Hosted Webhook URL Usage and added project_id into the webhook payload
This commit introduces the capability of using a Self-Hosted Webhook URL. The application now checks for a self-hosted URL before querying the database for the webhook settings. If a Self-Hosted Webhook URL is set in the environment variables, it will be used directly, diminishing unnecessary database queries.
This commit is contained in:
parent
f17cb1a0d4
commit
6208f4207d
@ -50,3 +50,6 @@ PROXY_USERNAME=
|
|||||||
PROXY_PASSWORD=
|
PROXY_PASSWORD=
|
||||||
# set if you'd like to block media requests to save proxy bandwidth
|
# set if you'd like to block media requests to save proxy bandwidth
|
||||||
BLOCK_MEDIA=
|
BLOCK_MEDIA=
|
||||||
|
|
||||||
|
# Set this to the URL of your webhook when using the self-hosted version of FireCrawl
|
||||||
|
SELF_HOSTED_WEBHOOK_URL=https://webhook.site/9d867d67-f77a-409b-aad6-73ebb2a264c2
|
@ -2,11 +2,15 @@ import { supabase_service } from "./supabase";
|
|||||||
|
|
||||||
export const callWebhook = async (teamId: string, data: any) => {
|
export const callWebhook = async (teamId: string, data: any) => {
|
||||||
try {
|
try {
|
||||||
const { data: webhooksData, error } = await supabase_service
|
const selfHostedUrl = process.env.SELF_HOSTED_WEBHOOK_URL;
|
||||||
.from('webhooks')
|
let webhookUrl = selfHostedUrl;
|
||||||
.select('url')
|
|
||||||
.eq('team_id', teamId)
|
if (!selfHostedUrl) {
|
||||||
.limit(1);
|
const { data: webhooksData, error } = await supabase_service
|
||||||
|
.from('webhooks')
|
||||||
|
.select('url')
|
||||||
|
.eq('team_id', teamId)
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(`Error fetching webhook URL for team ID: ${teamId}`, error.message);
|
console.error(`Error fetching webhook URL for team ID: ${teamId}`, error.message);
|
||||||
@ -17,6 +21,9 @@ export const callWebhook = async (teamId: string, data: any) => {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
webhookUrl = webhooksData[0].url;
|
||||||
|
}
|
||||||
|
|
||||||
let dataToSend = [];
|
let dataToSend = [];
|
||||||
if (data.result.links && data.result.links.length !== 0) {
|
if (data.result.links && data.result.links.length !== 0) {
|
||||||
for (let i = 0; i < data.result.links.length; i++) {
|
for (let i = 0; i < data.result.links.length; i++) {
|
||||||
@ -28,13 +35,14 @@ export const callWebhook = async (teamId: string, data: any) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await fetch(webhooksData[0].url, {
|
await fetch(webhookUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
success: data.success,
|
success: data.success,
|
||||||
|
project_id: data.project_id,
|
||||||
data: dataToSend,
|
data: dataToSend,
|
||||||
error: data.error || undefined,
|
error: data.error || undefined,
|
||||||
}),
|
}),
|
||||||
|
Loading…
Reference in New Issue
Block a user