Skip to content

Commit

Permalink
Send message about new user to slack via bot
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubno committed Nov 8, 2023
1 parent aa0dcca commit 8489eea
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions supabase/functions/new_user/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { serve } from 'https://deno.land/[email protected]/http/server.ts'
import { WebClient } from 'https://deno.land/x/[email protected]/mod.js'

const SLACK_API_TOKEN = Deno.env.get('SLACK_NEW_USER_FEEDBACK_APP_OAUTH_TOKEN')
if (!SLACK_API_TOKEN) {
const SLACK_WEBHOOK_URL = Deno.env.get('SLACK_USER_SIGNUP_WEBHOOK_URL')
if (!SLACK_WEBHOOK_URL) {
throw new Error('Missing SLACK_NEW_USER_FEEDBACK_APP_OAUTH_TOKEN environment variable')
}
const SLACK_CHANNEL = 'user-signups'

console.log('Will create slack client')

const slackClient = new WebClient(SLACK_API_TOKEN)

console.log('Slack client created')

function sendSlackMessage(email: string) {
const message = `:fire: *New User Signed Up *\n*User*\n${email}\n`

return slackClient.chat.postMessage({
channel: SLACK_CHANNEL,
text: message,
link_names: true,
return fetch(SLACK_WEBHOOK_URL,{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
channel: SLACK_CHANNEL,
text: message,
}),
})
}

Expand Down

0 comments on commit 8489eea

Please sign in to comment.