-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from theapexlab/APEX-1560-ask-present-ideas-me…
…ssage Apex-1560 - Ask present ideas message
- Loading branch information
Showing
24 changed files
with
756 additions
and
189 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { and, eq, not } from "drizzle-orm"; | ||
|
||
import { db } from "@/db/index"; | ||
import { users } from "@/db/schema"; | ||
|
||
export const getTeammates = async (teamId: string, userId: string) => { | ||
const teammates = await db | ||
.select({ | ||
id: users.id, | ||
}) | ||
.from(users) | ||
.where(and(eq(users.teamId, teamId), not(eq(users.id, userId)))); | ||
|
||
return teammates.map((teammate) => teammate.id); | ||
}; |
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
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
34 changes: 34 additions & 0 deletions
34
packages/core/services/slack/constructAskPresentIdeasMessage.ts
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { ChatPostMessageArguments } from "@slack/web-api"; | ||
|
||
import { makeTextBlock } from "./messageItems"; | ||
|
||
type Arguments = { | ||
birthdayPerson: string; | ||
user: string; | ||
name: string; | ||
eventId?: string; | ||
}; | ||
|
||
export const constructAskPresentIdeasMessage = ({ | ||
birthdayPerson, | ||
user, | ||
name, | ||
eventId, | ||
}: Arguments): ChatPostMessageArguments => | ||
({ | ||
channel: user, | ||
metadata: { | ||
event_type: "askPresentIdeas", | ||
event_payload: { | ||
eventId: eventId || "", | ||
birthdayPerson, | ||
}, | ||
}, | ||
text: `Hey, <@${user}>! <@${birthdayPerson}>'s birthday is in 2 months. Do you have any present ideas?`, | ||
blocks: [ | ||
makeTextBlock(`Hey ${name}! 👋`), | ||
makeTextBlock( | ||
`It's <@${birthdayPerson}>'s birthday is in 2 months. Do you have any present ideas?`, | ||
), | ||
], | ||
}) satisfies ChatPostMessageArguments; |
12 changes: 3 additions & 9 deletions
12
packages/core/services/slack/constructBirthdayConfirmedMessage.ts
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,16 +1,10 @@ | ||
import type { ChatReplaceMessageArguments } from "@/types/ChatReplaceMessageArguments"; | ||
|
||
import { makeTextBlock } from "./messageItems"; | ||
|
||
export const constructBirthdayConfirmedMessage = | ||
(): ChatReplaceMessageArguments => ({ | ||
replace_original: true, | ||
text: "Thanks for submitting your birthday! 🎉", | ||
blocks: [ | ||
{ | ||
type: "section", | ||
text: { | ||
type: "mrkdwn", | ||
text: `Thanks for submitting your birthday! 🎉`, | ||
}, | ||
}, | ||
], | ||
blocks: [makeTextBlock(`Thanks for submitting your birthday! 🎉`)], | ||
}); |
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
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
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import type { ActionsBlock, SectionBlock } from "@slack/web-api"; | ||
|
||
export const makeTextBlock = (text: string): SectionBlock => ({ | ||
type: "section", | ||
text: { | ||
type: "mrkdwn", | ||
text, | ||
}, | ||
}); | ||
|
||
export const makeTextBlockWithDatepicker = ( | ||
text: string, | ||
actionId: string, | ||
): SectionBlock => ({ | ||
...makeTextBlock(text), | ||
accessory: { | ||
type: "datepicker", | ||
initial_date: "1995-01-01", | ||
placeholder: { | ||
type: "plain_text", | ||
text: "Select a date", | ||
emoji: true, | ||
}, | ||
action_id: actionId, | ||
}, | ||
}); | ||
|
||
export const makeActionsBlock = ( | ||
yesActionId: string, | ||
noActionId: string, | ||
yesValue: string, | ||
noValue: string, | ||
): ActionsBlock => ({ | ||
type: "actions", | ||
elements: [ | ||
{ | ||
type: "button", | ||
text: { | ||
type: "plain_text", | ||
emoji: true, | ||
text: "Yes", | ||
}, | ||
style: "primary", | ||
action_id: yesActionId, | ||
value: yesValue, | ||
}, | ||
{ | ||
type: "button", | ||
text: { | ||
type: "plain_text", | ||
emoji: true, | ||
text: "No", | ||
}, | ||
style: "danger", | ||
action_id: noActionId, | ||
value: noValue, | ||
}, | ||
], | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import dayjs from "dayjs"; | ||
import utc from "dayjs/plugin/utc"; | ||
|
||
dayjs.extend(utc); | ||
|
||
import { getBirthdays } from "@/db/queries/getBirthdays"; | ||
import { publishEvent } from "@/utils/eventBridge/publishEvent"; | ||
import { cronHandler } from "@/utils/lambda/cronHandler"; | ||
|
||
export const handler = cronHandler(async (eventId?: string) => { | ||
const today = dayjs().utc().startOf("day"); | ||
|
||
const users = await getBirthdays(today.add(2, "month")); | ||
|
||
await Promise.all( | ||
users.map((user) => | ||
publishEvent("askPresentIdeasFromTeam", { | ||
team: user.teamId, | ||
birthdayPerson: user.id, | ||
eventId, | ||
}), | ||
), | ||
); | ||
|
||
return { | ||
users, | ||
message: users.length ? "Sent present ideas requests" : "No birthdays", | ||
}; | ||
}); |
Oops, something went wrong.