-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send message about new user to slack via bot
- Loading branch information
Showing
1 changed file
with
11 additions
and
11 deletions.
There are no files selected for viewing
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
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, | ||
}), | ||
}) | ||
} | ||
|
||
|