Skip to content

Commit

Permalink
Merge pull request #14 from totegsito/feat/11-empty-non-celebrate-mes…
Browse files Browse the repository at this point in the history
…sage

feat(#11): add default message for days without birthdays
  • Loading branch information
inigomarquinez authored Feb 15, 2023
2 parents 6cbdcb5 + 4a93450 commit 7c8d169
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 16 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:',
},
],
};
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)
);
};

0 comments on commit 7c8d169

Please sign in to comment.