Skip to content

Commit

Permalink
feat(#11): add default message when there is nothing to celebrate
Browse files Browse the repository at this point in the history
  • Loading branch information
totegsito committed Feb 14, 2023
1 parent 2994eb8 commit 4a93450
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 27 deletions.
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:',
},
],
};
66 changes: 39 additions & 27 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,21 +266,10 @@ export const publishEmployeesCelebrations = async (
],
}))
);
} else {
birthdaysBlocks.push({
type: 'context',
elements: [
{
type: 'mrkdwn',
plain_text:
':mad-hatter::teapot: *A very Merry Unbirthday to you all!* :mad-hatter::teapot:',
},
],
type: 'divider',
});
}
birthdaysBlocks.push({
type: 'divider',
});

// ANNIVERSARY
const anniversaries = employees
Expand Down Expand Up @@ -368,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)
);
};

0 comments on commit 4a93450

Please sign in to comment.