Skip to content

Commit

Permalink
ping us in discord when a citizen mints
Browse files Browse the repository at this point in the history
  • Loading branch information
lyoshenka committed Mar 7, 2024
1 parent 3b6f915 commit 5ab1635
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/discord.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import fetch from 'node-fetch'

export async function sendToDiscord(msg: string) {
const url = process.env.DISCORD_MINTBOT_URL
if (!url) {
console.log('discord logs url missing from env vars')
return
}

try {
return fetch(url, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
username: 'MintBot',
// avatar_url: "",
content: msg,
}),
})
} catch (e: unknown) {
console.error(e)
}
}
5 changes: 5 additions & 0 deletions pages/api/v2/checkout/stripe-webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ProfileWithInviteQueryInclude,
ProfileWithInviteRelations,
} from '@/utils/profile'
import { sendToDiscord } from '@/lib/discord'

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY ?? '', {
apiVersion: '2023-08-16', // latest version at the time I wrote this
Expand Down Expand Up @@ -214,6 +215,10 @@ async function postProcessCart(cart: CartWithRelations) {
}

await grantOrExtendCitizenship(profile)

await sendToDiscord(
`New citizen minted via checkout: ${profile.name} https://cabin.city/profile/${profile.externId}`
)
}

// must match CartQueryInclude below
Expand Down
1 change: 1 addition & 0 deletions types/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface Env {
STRIPE_WEBHOOK_SECRET: string
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY: string
CONVERTKIT_API_KEY: string
DISCORD_MINTBOT_URL: string
}

declare global {
Expand Down

0 comments on commit 5ab1635

Please sign in to comment.