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

Feature: Create queue for Calomentor communications #100

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
82 changes: 82 additions & 0 deletions queues/communications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import {
SQSBatchItemFailure,
SQSHandler,
} from "aws-lambda";
import { AWSError, SQS } from "aws-sdk";
import { SendMessageResult } from "aws-sdk/clients/sqs";
import { PromiseResult } from "aws-sdk/lib/request";
import { QueueData, QUEUETYPES } from "../types";

const sqs: SQS = new SQS();

export const senderQueueMail: (
data: QueueData
) => Promise<{ data: PromiseResult<SendMessageResult, AWSError> }> = async (
data
) => {
try {
const sqsSender = await sqs
.sendMessage({
QueueUrl: process.env.QUEUE_COMMUNICATIONS_URL,
MessageBody: JSON.stringify(data),
})
.promise();
return {
data: sqsSender,
};
} catch (error) {
throw new Error("Unexpected error sending the message to a queue.");
}
};

export const receiverQueueMail: SQSHandler = (event, _, callback) => {
const batchItemFailures: SQSBatchItemFailure[] = [];

for (const record of event.Records) {
const body = JSON.parse(record.body);
switch (body.type) {
case QUEUETYPES.MENTEE_MAIL: {
try {
//TODO: send mentee mail
} catch (error) {
batchItemFailures.push({ itemIdentifier: record.messageId });
}
break;
}
case QUEUETYPES.MENTOR_MAIL: {
try {
//TODO: send mentor mail
} catch (error) {
batchItemFailures.push({ itemIdentifier: record.messageId });
}
break;
}
case QUEUETYPES.MENTEE_DM: {
try {
//TODO: send mentee dm
} catch (error) {
batchItemFailures.push({ itemIdentifier: record.messageId });
}
break;
}
case QUEUETYPES.MENTOR_DM: {
try {
//TODO: send mentor dm
} catch (error) {
batchItemFailures.push({ itemIdentifier: record.messageId });
}
break;
}
case QUEUETYPES.NOTIFICATION: {
try {
//TODO: send notification
} catch (error) {
batchItemFailures.push({ itemIdentifier: record.messageId });
}
break;
}
}
}

return callback(null, { batchItemFailures });
};
47 changes: 47 additions & 0 deletions types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,50 @@ export interface MentorshipResponse {
confirmationAttempt?: number;
reminderAttempt?: number;
}


export enum QUEUETYPES {
MENTEE_MAIL = "MENTEE_MAIL",
MENTEE_DM = "MENTEE_DM",
MENTOR_MAIL = "MENTOR_MAIL",
MENTOR_DM = "MENTOR_DM",
NOTIFICATION = "NOTIFICATION",
}

export enum COMMUNICATIONTYPES {
CREATE = "CREATE",
REMINDER = "REMINDER",
FEEDBACK = "FEEDBACK",
CANCEL = "CANCEL",
CONFIRMATION_REQUEST = "CONFIRMATION_REQUEST",
WARNING = "WARNING",
}

type QueueDataBase = {
type: QUEUETYPES;
mentee_id: string;
mentor_id: string;
mentorship_date: Date;
};

type QueueMail = QueueDataBase & {
mentee_email: string;
mentee_name: string;
mentor_email: string;
mentor_name: string;
duration: 30 | 45 | 60;
mentorship_id: string;
mentee_timezone: string;
mentor_timezone: string;
mail_type: COMMUNICATIONTYPES;
};

type QueueNotification = QueueDataBase & {
notification_type: COMMUNICATIONTYPES;
};

type QueueDM = QueueDataBase & {
dm_type: COMMUNICATIONTYPES;
};

export type QueueData = QueueDM | QueueMail | QueueNotification;