-
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 #7 from theapexlab/birthday-interactions
APEX-1587 - Birthday interactions
- Loading branch information
Showing
40 changed files
with
976 additions
and
185 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
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
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,24 @@ | ||
import { users } from "./schema"; | ||
import { db } from "."; | ||
|
||
type Args = { | ||
user: string; | ||
teamId: string; | ||
birthday: string; | ||
}; | ||
|
||
export const saveBirthday = async ({ birthday, teamId, user }: Args) => { | ||
await db | ||
.insert(users) | ||
.values({ | ||
id: user, | ||
teamId, | ||
birthday: new Date(birthday), | ||
}) | ||
.onConflictDoUpdate({ | ||
target: [users.id, users.teamId], | ||
set: { | ||
birthday: new Date(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
63 changes: 63 additions & 0 deletions
63
packages/core/services/slack/constructAskBirthdayMessage.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,63 @@ | ||
import type { ChatPostMessageArguments } from "@slack/web-api"; | ||
|
||
import type { ChatReplaceMessageArguments } from "@/types/ChatReplaceMessageArguments"; | ||
import { pickBirthdayActionId } from "@/types/SlackInteractionRequest"; | ||
|
||
type Arguments = { | ||
user: string; | ||
name: string; | ||
eventId?: string; | ||
}; | ||
|
||
const constructBaseAskBirthdayMessage = ({ | ||
name, | ||
eventId, | ||
}: Arguments): Omit<ChatPostMessageArguments, "channel"> => ({ | ||
text: "Please share your birthday with us! 🥳", | ||
blocks: [ | ||
{ | ||
type: "section", | ||
text: { | ||
type: "mrkdwn", | ||
text: `Hey ${name}! 👋`, | ||
}, | ||
}, | ||
{ | ||
type: "section", | ||
text: { | ||
type: "mrkdwn", | ||
text: "Please share your birthday with us! 🥳", | ||
}, | ||
accessory: { | ||
type: "datepicker", | ||
initial_date: "1995-01-01", | ||
placeholder: { | ||
type: "plain_text", | ||
text: "Select a date", | ||
emoji: true, | ||
}, | ||
action_id: pickBirthdayActionId, | ||
}, | ||
}, | ||
], | ||
metadata: { | ||
event_type: "askBirthday", | ||
event_payload: { | ||
originalEventId: eventId, | ||
}, | ||
}, | ||
}); | ||
|
||
export const constructAskBirthdayMessage = ( | ||
args: Arguments, | ||
): ChatPostMessageArguments => ({ | ||
...constructBaseAskBirthdayMessage(args), | ||
channel: args.user, | ||
}); | ||
|
||
export const constructAskBirthdayMessageReplacement = ( | ||
args: Arguments, | ||
): ChatReplaceMessageArguments => ({ | ||
...constructBaseAskBirthdayMessage(args), | ||
replace_original: true, | ||
}); |
16 changes: 16 additions & 0 deletions
16
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { ChatReplaceMessageArguments } from "@/types/ChatReplaceMessageArguments"; | ||
|
||
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! 🎉`, | ||
}, | ||
}, | ||
], | ||
}); |
55 changes: 55 additions & 0 deletions
55
packages/core/services/slack/constructConfirmBirthdayMessage.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,55 @@ | ||
import type { ChatReplaceMessageArguments } from "@/types/ChatReplaceMessageArguments"; | ||
import { | ||
birthdayConfirmActionId, | ||
birthdayIncorrectActionId, | ||
} from "@/types/SlackInteractionRequest"; | ||
|
||
export const constructConfirmBirthdayMessage = ( | ||
birthday: string, | ||
): ChatReplaceMessageArguments => | ||
({ | ||
replace_original: true, | ||
text: "Confirm your birthday", | ||
blocks: [ | ||
{ | ||
type: "section", | ||
text: { | ||
type: "mrkdwn", | ||
text: `Are you sure your birthday is ${birthday}?`, | ||
}, | ||
}, | ||
{ | ||
type: "actions", | ||
elements: [ | ||
{ | ||
type: "button", | ||
text: { | ||
type: "plain_text", | ||
emoji: true, | ||
text: "Yes", | ||
}, | ||
style: "primary", | ||
action_id: birthdayConfirmActionId, | ||
value: birthday, | ||
}, | ||
{ | ||
type: "button", | ||
text: { | ||
type: "plain_text", | ||
emoji: true, | ||
text: "No", | ||
}, | ||
style: "danger", | ||
action_id: birthdayIncorrectActionId, | ||
value: birthday, | ||
}, | ||
], | ||
}, | ||
], | ||
metadata: { | ||
event_type: "confirmBirthday", | ||
event_payload: { | ||
birthday, | ||
}, | ||
}, | ||
}) satisfies ChatReplaceMessageArguments; |
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,8 @@ | ||
import type { ChatPostMessageArguments } from "@slack/web-api"; | ||
|
||
export type ChatReplaceMessageArguments = Omit< | ||
ChatPostMessageArguments, | ||
"channel" | ||
> & { | ||
replace_original: boolean; | ||
}; |
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,39 @@ | ||
import { z } from "zod"; | ||
|
||
export const pickBirthdayActionId = "pickBirthday"; | ||
export const birthdayConfirmActionId = "birthdayConfirm"; | ||
export const birthdayIncorrectActionId = "birthdayIncorrect"; | ||
|
||
export const SlackInteractionRequestSchema = z.object({ | ||
type: z.literal("block_actions"), | ||
user: z.object({ | ||
id: z.string(), | ||
team_id: z.string(), | ||
}), | ||
actions: z | ||
.array( | ||
z.discriminatedUnion("type", [ | ||
z.object({ | ||
type: z.literal("datepicker"), | ||
selected_date: z.string(), | ||
action_id: z.literal(pickBirthdayActionId), | ||
action_ts: z.string(), | ||
}), | ||
z.object({ | ||
type: z.literal("button"), | ||
action_id: z.union([ | ||
z.literal(birthdayConfirmActionId), | ||
z.literal(birthdayIncorrectActionId), | ||
]), | ||
action_ts: z.string(), | ||
value: z.string(), | ||
}), | ||
]), | ||
) | ||
.length(1), | ||
response_url: z.string(), | ||
}); | ||
|
||
export type SlackInteractionRequest = z.infer< | ||
typeof SlackInteractionRequestSchema | ||
>; |
Oops, something went wrong.