mirror of
https://github.com/stronk-dev/RandomChad.git
synced 2025-07-05 10:35:08 +02:00
✨ add discord webhook functionality to the changing room
This commit is contained in:
parent
2c1f80a045
commit
ddd33d4851
33
functions/integrations/discord.js
Normal file
33
functions/integrations/discord.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
const functions = require( 'firebase-functions' )
|
||||||
|
const { discord } = functions.config()
|
||||||
|
const fetch = require( 'isomorphic-fetch' )
|
||||||
|
|
||||||
|
exports.notifyDiscordWebhook = async function( username, content, avatar_url, image_title, image_url ) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Construct discord webhook message
|
||||||
|
const message = {
|
||||||
|
username,
|
||||||
|
content,
|
||||||
|
avatar_url,
|
||||||
|
embeds: [ {
|
||||||
|
title: image_title, image: { url: image_url }
|
||||||
|
} ]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct request options
|
||||||
|
const options = {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify( message )
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make webhook request
|
||||||
|
await fetch( discord.webhookurl, options )
|
||||||
|
|
||||||
|
} catch( e ) {
|
||||||
|
console.error( 'Discord error ', e )
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user