Skip to content

Commit

Permalink
Add temporary console logs for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
innerlize committed Oct 6, 2023
1 parent aaa4c0c commit 2d7e5bd
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/commands/tarea/tarea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,37 @@ export const tareaCommandFunction = async ({
respond,
client,
}: Command): Promise<void> => {
console.log('HERE START TAREA COMMAND FUNCTION');
console.log('command: ', command);
console.log('client: ', client);

await ack();
try {
console.log('HERE ENTERS IN TRY BLOCK');
const { user } = (await client.users.info({
user: command.user_id,
})) as IUserClient;

console.log('user: ', user);
console.log('client.users.info property "user": ', command.user_id);

if (!user) {
throw new Error('Slack-api Error: User not found');
}

const classNumber = validateChannelName(command.channel_name);

console.log('classNumber: ', classNumber);

if (!classNumber) {
await respond(unknownCommandBlock());
return;
}

const submissionHasValidFormat = validateSubmissionFormat(command.text);

console.log('submissionHasValidFormat: ', submissionHasValidFormat);

if (!submissionHasValidFormat) {
await respond(wrongFormatSubmission());
return;
Expand All @@ -74,6 +86,8 @@ export const tareaCommandFunction = async ({
command.text
);

console.log('submissionHasSingleFormat: ', submissionHasSingleFormat);

if (!submissionHasSingleFormat) {
await respond(multipleSubmissionFormatsDetected());
return;
Expand All @@ -83,6 +97,11 @@ export const tareaCommandFunction = async ({
command.text
);

console.log(
'validateIsNotMultipleSubmissions: ',
validateIsNotMultipleSubmissions
);

if (!validateIsNotMultipleSubmissions && command.text.includes('```')) {
await respond(multipleBlocksOfCodeDetected());
return;
Expand All @@ -101,13 +120,17 @@ export const tareaCommandFunction = async ({
delivery: command.text,
});

console.log('validSubmissionFormat: ', validSubmissionFormat);

if (!validSubmissionFormat) {
await respond(wrongFormatBlock());
return;
}

const onlySubmissionContent = extractOnlySubmission(command.text);

console.log('onlySubmissionContent: ', onlySubmissionContent);

if (command.text && validSubmissionFormat) {
const tarea = await uploadTarea({
classNumber,
Expand All @@ -118,12 +141,25 @@ export const tareaCommandFunction = async ({
email: user.profile.email as string,
});

console.log('tarea: ', tarea);
console.log('uploadTarea property "classNumber": ', classNumber);
console.log('uploadTarea property "slackId": ', user.id);
console.log('uploadTarea property "delivery": ', onlySubmissionContent);
console.log(
'uploadTarea property "firstName": ',
user.profile.first_name
);
console.log('uploadTarea property "lastName": ', user.profile.last_name);
console.log('uploadTarea property "email": ', user.profile.email);

const messageResponse = await say(
`Tarea subida con éxito <@${
user.id
}>!\n\nTarea:\n${command.text.trim()}\n\n*Para agregar correcciones responder en este hilo.*`
);

console.log('messageResponse: ', messageResponse);

const thread: ICreateThreadDto = {
authorId: process.env.BOT_ID!,
studentId: tarea.studentId,
Expand All @@ -132,6 +168,13 @@ export const tareaCommandFunction = async ({
taskId: tarea.taskId,
};

console.log('thread: ', thread);
console.log('thread property "authorId": ', process.env.BOT_ID!);
console.log('thread property "studentId": ', tarea.studentId);
console.log('thread property "text": ', messageResponse.message?.text);
console.log('thread property "timestamp": ', messageResponse.ts);
console.log('thread property "taskId": ', tarea.taskId);

await threadApi.create(thread);
}
} catch (error) {
Expand Down
30 changes: 30 additions & 0 deletions src/events/message/messageNew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ export const handleSubmissionReplyNew: Middleware<
SlackEventMiddlewareArgs<'message'>,
StringIndexed
> = async ({ client, message, logger }) => {
console.log('HERE START HANDLE SUBMISSION REPLY NEW');

Check warning on line 12 in src/events/message/messageNew.ts

View workflow job for this annotation

GitHub Actions / build_and_test (16.x)

Unexpected console statement
if (
message.subtype === undefined &&
message.thread_ts &&
message.parent_user_id === env.BOT_ID
) {
console.log('Conditional data: ', message);

Check warning on line 18 in src/events/message/messageNew.ts

View workflow job for this annotation

GitHub Actions / build_and_test (16.x)

Unexpected console statement
try {
console.log('HERE ENTERS IN TRY BLOCK');

Check warning on line 20 in src/events/message/messageNew.ts

View workflow job for this annotation

GitHub Actions / build_and_test (16.x)

Unexpected console statement
const { messages: messagesFromChannel } =
await client.conversations.history({
latest: message.thread_ts,
Expand All @@ -23,10 +26,14 @@ export const handleSubmissionReplyNew: Middleware<
inclusive: true,
});

console.log('messages from channel: ', messagesFromChannel);

Check warning on line 29 in src/events/message/messageNew.ts

View workflow job for this annotation

GitHub Actions / build_and_test (16.x)

Unexpected console statement

const isSubmissionThread = isTaskSubmission(
messagesFromChannel![0].text!
);

console.log('isSubmissionThread: ', isSubmissionThread);

Check warning on line 35 in src/events/message/messageNew.ts

View workflow job for this annotation

GitHub Actions / build_and_test (16.x)

Unexpected console statement

if (!isSubmissionThread) {
return;
}
Expand All @@ -35,6 +42,9 @@ export const handleSubmissionReplyNew: Middleware<
user: message.user,
});

console.log('slackUser: ', slackUser);

Check warning on line 45 in src/events/message/messageNew.ts

View workflow job for this annotation

GitHub Actions / build_and_test (16.x)

Unexpected console statement
console.log('client.users.info property "user": ', message.user);

Check warning on line 46 in src/events/message/messageNew.ts

View workflow job for this annotation

GitHub Actions / build_and_test (16.x)

Unexpected console statement

const createReplyDto: ICreateReplyDto = {
authorId: slackUser!.id!,
text: message.text!,
Expand All @@ -45,14 +55,34 @@ export const handleSubmissionReplyNew: Middleware<
(slackUser!.profile!.real_name as string),
};

console.log('createReplyDto: ', createReplyDto);

Check warning on line 58 in src/events/message/messageNew.ts

View workflow job for this annotation

GitHub Actions / build_and_test (16.x)

Unexpected console statement
console.log('createReplyDto property "authorId": ', slackUser!.id);

Check warning on line 59 in src/events/message/messageNew.ts

View workflow job for this annotation

GitHub Actions / build_and_test (16.x)

Unexpected console statement
console.log('createReplyDto property "text": ', message.text);

Check warning on line 60 in src/events/message/messageNew.ts

View workflow job for this annotation

GitHub Actions / build_and_test (16.x)

Unexpected console statement
console.log('createReplyDto property "threadTS": ', message.thread_ts);
console.log('createReplyDto property "timestamp": ', message.ts);
console.log(
'createReplyDto property "username" (first option, display_name): ',
slackUser!.profile!.display_name
);
console.log(
'createReplyDto property "username" (second option, real_name): ',
slackUser!.profile!.real_name
);

const reply = await replyApi.create(createReplyDto);

console.log('reply: ', reply);

await client.reactions.add({
channel: message.channel,
name: 'white_check_mark',
timestamp: message.ts,
});

console.log('client.reactions.add property "channel": ', message.channel);
console.log('client.reactions.add property "name": ', 'white_check_mark');
console.log('client.reactions.add property "timestamp": ', message.ts);

logger.info(
`Reply with ID "${reply.id}" from user "${
slackUser!.id
Expand Down
Loading

0 comments on commit 2d7e5bd

Please sign in to comment.