How to send database webhook to discord with supabase

how do i add my json body? like this example for a webhook https://gist.github.com/Birdie0/78ee79402a4301b1faf412ab5f1cdcf9#example-for-a-webhook
Gist
How to use Discord Webhooks
How to use Discord Webhooks. GitHub Gist: instantly share code, notes, and snippets.
No description
6 Replies
ducky
ducky2y ago
When you set up the Webhook in Supabase, you choose the database table that it "listens" to. When a new row is inserted (or updated, if you've set it up that way), the contents of that row are sent as the body of the webhook as JSON.
RAVEN
RAVENOP2y ago
oh okay, that tells me its not possible to send a custom message to discord when a row gets inserted, or should i try with a custom trigger?
garyaustin
garyaustin2y ago
Yes, just use a trigger with the http or pg_net extension.
RAVEN
RAVENOP2y ago
where do i see the functions error log `? my function definition looks like this
DECLARE
discord_webhook_url TEXT := 'https://discord.com/api/webhooks/...';
request_data JSONB;
BEGIN
request_data := jsonb_build_object(
'content', 'Your message goes here',
'username', 'Your Webhook Username'
);

PERFORM pg_net.post(
discord_webhook_url,
request_data::TEXT,
'Content-Type: application/json'
);

RETURN NULL;

EXCEPTION
WHEN OTHERS THEN
RAISE NOTICE 'Error sending message to Discord: %', SQLERRM;
RETURN NULL;
END;
DECLARE
discord_webhook_url TEXT := 'https://discord.com/api/webhooks/...';
request_data JSONB;
BEGIN
request_data := jsonb_build_object(
'content', 'Your message goes here',
'username', 'Your Webhook Username'
);

PERFORM pg_net.post(
discord_webhook_url,
request_data::TEXT,
'Content-Type: application/json'
);

RETURN NULL;

EXCEPTION
WHEN OTHERS THEN
RAISE NOTICE 'Error sending message to Discord: %', SQLERRM;
RETURN NULL;
END;
i have linked it to a trigger, but it does not send any webhook to my discord channel @garyaustin
garyaustin
garyaustin2y ago
The logs for functions are in the Postgres logs. You can use raise log 'say something and var = %',var; between begin and end to debug a bit.
garyaustin
garyaustin2y ago
This shows using jsonb for the values not text or strings...
No description

Did you find this page helpful?