Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#11): add default message for days without birthdays #14

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/constants/defaultMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
type: 'context',
elements: [
{
type: 'mrkdwn',
plain_text:
':mad-hatter::teapot: *A very Merry Unbirthday to you all!* :mad-hatter::teapot:',
},
],
};
54 changes: 38 additions & 16 deletions src/publisher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import moment from 'moment';

import defaultMessage from './constants/defaultMessage';

import {
TBambooHREmployeeAtOffice,
TBambooHREmployeeExtended,
Expand Down Expand Up @@ -264,7 +266,6 @@ export const publishEmployeesCelebrations = async (
],
}))
);

birthdaysBlocks.push({
type: 'divider',
});
Expand Down Expand Up @@ -358,22 +359,43 @@ export const publishEmployeesCelebrations = async (
});
}

const message = {
text: "🥳 Let's celebrate together",
blocks: [
{
type: 'header',
text: {
type: 'plain_text',
text: "🥳 Let's celebrate together",
emoji: true,
const celebrationMessages = [
...firstDayBlocks,
...birthdaysBlocks,
...anniversariesBlocks,
];

const buildMessageToSend = (messages: object[]) => {
const base = {
text: "🥳 Let's celebrate together",
blocks: [
{
type: 'header',
text: {
type: 'plain_text',
text: "🥳 Let's celebrate together",
emoji: true,
},
},
},
...firstDayBlocks,
...birthdaysBlocks,
...anniversariesBlocks,
],
],
};

return messages.length > 0
? {
...base,
blocks: [...base.blocks, ...messages],
}
: {
...base,
blocks: {
...base.blocks,
defaultMessage,
},
};
};

await postSlackMessage(process.env.CELEBRATIONS_WEBHOOK_URL ?? '', message);
await postSlackMessage(
process.env.CELEBRATIONS_WEBHOOK_URL ?? '',
buildMessageToSend(celebrationMessages)
);
};