Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/hudl/CalendarToSlack into…
Browse files Browse the repository at this point in the history
… export-import-settings
  • Loading branch information
james-vaughn committed Oct 24, 2024
2 parents 845b6b0 + 5856be4 commit 709d1fa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion serverless-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ lambda:
slackbot:
roleName: hudl-cal2slack-lambda-slackbot
policyName: hudl-cal2slack-lambda-slackbot-policy
secretsPrefix: hudl/internal/cal2slack/slackbot-secrets
secretsPrefix: hudl/internal/cal2slack
testSecret:
roleName: hudl-cal2slack-lambda-slackbot
policyName: hudl-cal2slack-lambda-slackbot-policy
Expand Down
11 changes: 11 additions & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ functions:
- http:
path: 'slack/install'
method: get
role: slackbotRole
create-user:
handler: src/index.createUser
events:
Expand Down Expand Up @@ -124,6 +125,16 @@ resources:
- Ref: 'AWS::Region'
- Ref: 'AWS::AccountId'
- 'table/cal2slack-usersettings'
- Effect: Allow
Action:
- secretsmanager:GetSecretValue
Resource:
- 'Fn::Join':
- ':'
- - 'arn:aws:secretsmanager'
- Ref: 'AWS::Region'
- Ref: 'AWS::AccountId'
- 'secret:${self:custom.lambda.slackbot.secretsPrefix}/*'
- Effect: 'Allow'
Action:
- lambda:InvokeFunction
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {InvokeCommand, LambdaClient} from '@aws-sdk/client-lambda';
import { AuthorizationCode } from 'simple-oauth2';
import {LogLevel, WebClient} from '@slack/web-api';
import {WebClient} from '@slack/web-api';
import {CalendarEvent, getEventsForUser, ShowAs} from './services/calendar';
import {
getAllUserSettings,
Expand Down Expand Up @@ -155,6 +155,7 @@ export const authorizeMicrosoftGraph: Handler = async (event: any) => {
};

export const slackInstall: Handler = async () => {
console.log('Slack install requested.')
const clientId = await getSlackClientIdWithKey('clientId');

return {
Expand Down Expand Up @@ -200,8 +201,7 @@ export const createUser: Handler = async (event: any) => {
const user: string = tokenResult.token.user_id as string;

const slackClient = new WebClient(tokenStr);
const userInfo = await slackClient.users.info({ token: tokenStr, user: user })

const userInfo = await slackClient.users.info({ token: tokenStr, user: user });

if (userInfo.error) {
console.error('Error getting profile from Slack', userInfo.error);
Expand Down
4 changes: 3 additions & 1 deletion src/services/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export const setUserPresence = async (email: string, token: string | undefined,

try {
const result = await slackClient.users.setPresence({ presence });
throw result.error;
if (!result.ok) {
throw result.error;
}
} catch (error) {
await handleError(error, email);
}
Expand Down

0 comments on commit 709d1fa

Please sign in to comment.