Skip to content

Commit

Permalink
chore: add more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Balint Dolla committed Oct 25, 2023
1 parent c505765 commit 0c8fdd0
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:

- name: Set secrets
run: |
npx sst secrets set SLACK_LOG_LEVEL debug --stage ${{ env.STAGE }}
npx sst secrets set SLACK_LOG_LEVEL "${{ secrets.SLACK_LOG_LEVEL_TEST }}" --stage ${{ env.STAGE }}
npx sst secrets set SLACK_BOT_TOKEN "${{ secrets.SLACK_BOT_TOKEN_TEST }}" --stage ${{ env.STAGE }}
npx sst secrets set SLACK_SIGNING_SECRET "${{ secrets.SLACK_SIGNING_SECRET_TEST }}" --stage ${{ env.STAGE }}
npx sst secrets set CORE_SLACK_CHANNEL_ID "${{ secrets.CORE_SLACK_CHANNEL_ID_TEST }}" --stage ${{ env.STAGE }}
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"@typescript-eslint/parser": "^6.7.5",
"aws-cdk-lib": "2.95.1",
"constructs": "10.2.69",
"dotenv": "^16.3.1",
"eslint": "^8.51.0",
"eslint-config-prettier": "^9.0.0",
"eslint-define-config": "^1.24.1",
Expand Down
3 changes: 3 additions & 0 deletions packages/functions/events/askBirthday.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import { handleEvent } from "@/utils/eventBridge/handleEvent";

export const handler = handleEvent("askBirthday", async ({ user, eventId }) => {
try {
console.log(`ASK_BIRTHDAY: ${user} ${eventId}`);

const userInfo = await getUserInfo(user);

if (!userInfo.user || userInfo.user.is_bot) {
console.log("ASK_BIRTHDAY: User is a bot, ignoring");
return;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/functions/events/botJoined.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export const handler = handleEvent(
"botJoined",
async ({ channel, eventId }) => {
try {
console.log(`BOT_JOINED: ${channel} ${eventId}`);

const users = await getChannelMembers(channel);

for (const user of users) {
Expand Down
7 changes: 7 additions & 0 deletions packages/functions/events/memberJoinedChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import { publishEvent } from "@/utils/eventBridge/publishEvent";

export const handler = handleEvent("memberJoinedChannel", async (event) => {
try {
console.log(
`MEMBER_JOINED_CHANNEL: ${event.channel} ${event.user} ${event.eventId}`,
);

if (event.channel !== Config.CORE_SLACK_CHANNEL_ID) {
console.log(
`MEMBER_JOINED_CHANNEL: Ignoring event from channel ${event.channel}`,
);
return;
}

Expand Down
7 changes: 5 additions & 2 deletions packages/functions/utils/eventBridge/publishEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ const client = new EventBridgeClient({});
export const publishEvent = <T extends EventType>(
event: T,
payload: Events[T],
) =>
client.send(
) => {
console.log("Publishing event", event, payload);

return client.send(
new PutEventsCommand({
Entries: [
{
Expand All @@ -23,3 +25,4 @@ export const publishEvent = <T extends EventType>(
],
}),
);
};
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/integration/slackEvents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("Slack events", () => {
expect(chat.messages![0].text).toEqual(
"Please share your birthday with us! :birthday:",
);
}, 20_000);
}, 60_000);

it("Should send DM to all users when bot joins the channel", async () => {
const eventId = "E002";
Expand All @@ -74,5 +74,5 @@ describe("Slack events", () => {
expect(chat.messages![0].text).toEqual(
"Please share your birthday with us! :birthday:",
);
}, 20_000);
}, 60_000);
});
2 changes: 1 addition & 1 deletion tests/utils/waitForDm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const waitForDm = async (app: App, eventId: string) =>
return chat;
},
{
timeout: 15_000,
timeout: 60_000,
interval: 1_000,
},
);

0 comments on commit 0c8fdd0

Please sign in to comment.