Last active
September 26, 2024 18:14
-
-
Save markflorkowski/90e90f7ccb135b404e6559844f280074 to your computer and use it in GitHub Desktop.
Clerk New Users - Discord Transform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function handler(webhook) { | |
const {data: user} = webhook.payload; | |
// Extract relevant details | |
const emailAddress = user.email_addresses?.[0]?.email_address || 'Unknown user'; | |
const firstName = user.first_name || ''; | |
const lastName = user.last_name || ''; | |
const fullName = `${firstName} ${lastName}`.trim() || emailAddress; | |
const profileImageUrl = user.profile_image_url || 'https://www.gravatar.com/avatar?d=mp'; | |
const createdAt = new Date(user.created_at).toLocaleString(); | |
const githubAccount = user.external_accounts?.[0]?.username || "Unknown" | |
// List of common email providers | |
const commonProviders = [ | |
"gmail.com", "yahoo.com", "hotmail.com", "outlook.com", "aol.com", "icloud.com", | |
"mail.com", "live.com", "msn.com", "protonmail.com", "zoho.com", | |
"yandex.com", "gmx.com", "inbox.com", "mail.ru", "lycos.com", | |
"me.com", "tutanota.com", "hushmail.com", "fastmail.com", "rocketmail.com", | |
"mac.com", "bigpond.com", "bellsouth.net", "verizon.net", "cox.net", | |
"shaw.ca", "sympatico.ca", "rogers.com", "earthlink.net", "comcast.net", | |
"charter.net", "frontier.com", "windstream.net", "optimum.net", "optonline.net", | |
"sbcglobal.net", "att.net", "netscape.net", "rediffmail.com", "indiatimes.com", | |
"ozemail.com.au", "bigpond.net.au", "btinternet.com", "talktalk.net", "sky.com", | |
"ntlworld.com", "virginmedia.com", "blueyonder.co.uk", "tiscali.co.uk", "orange.fr", | |
"laposte.net", "free.fr", "sfr.fr", "neuf.fr", "aliceadsl.fr", | |
"libero.it", "virgilio.it", "tiscali.it", "tin.it", "email.it", | |
"poste.it", "teletu.it", "seznam.cz", "zoznam.sk", "centrum.cz", | |
"volny.cz", "atlas.cz", "onet.pl", "interia.pl", "o2.pl", | |
"wp.pl", "gazeta.pl", "poczta.fm", "rambler.ru", "bk.ru", | |
"list.ru", "inbox.ru", "pm.me", "hey.com", ".edu" | |
]; | |
const emailDomain = emailAddress.split('@')[1]; | |
const isCommonProvider = commonProviders.some(x => emailDomain.includes(x)); | |
// Create the embed object | |
const embed = { | |
title: '🎉 New User Signup! 🎉', | |
color: isCommonProvider ? 0xC0C0C0 : 0xFFD700, // Gray for common, Gold for uncommon | |
fields: [ | |
{ name: 'Name', value: fullName, inline: true }, | |
{ name: 'Github', value: githubAccount, inline: true }, | |
{ name: 'Email', value: emailAddress, inline: false }, | |
{ name: 'Account Created At', value: createdAt, inline: false }, | |
], | |
thumbnail: { url: profileImageUrl } | |
}; | |
// Return the modified webhook object with the embed object and button component | |
return { | |
...webhook, | |
payload: { | |
"embeds": [embed], | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment