Skip to content

feat(PM-1173): Notify all copilots on copilot opportunity #815

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

Merged
merged 23 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
fix: added external action email kaufka type
  • Loading branch information
hentrymartin committed Jun 5, 2025
commit ae5952d9effabded8f703594530c3cb9b9e2f64c
4 changes: 2 additions & 2 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ export const CONNECT_NOTIFICATION_EVENT = {
POST_CREATED: 'connect.notification.project.post.created',
POST_UPDATED: 'connect.notification.project.post.edited',

// Copilot events
COPILOT_OPPORTUNITY_CREATED: 'connect.notification.project.copilot.opportunity.created',
// External action email
EXTERNAL_ACTION_EMAIL: 'external.action.email',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from COPILOT_OPPORTUNITY_CREATED to EXTERNAL_ACTION_EMAIL seems to alter the meaning of the event. Ensure that this change aligns with the intended functionality described in the pull request. If the intention is to notify all copilots, verify that the event name accurately reflects this purpose.

};

export const REGEX = {
Expand Down
12 changes: 4 additions & 8 deletions src/routes/copilotRequest/approveRequest.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,19 @@ module.exports = (req, data, existingTransaction) => {
const roles = await util.getRolesByRoleName('copilot', req.log, req.id);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function getRolesByRoleName now takes additional parameters req.log and req.id. Ensure that req is defined and available in this context to avoid potential runtime errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conver role name to enum/constant. Do not use hardcoded names.

req.log.info("getting subjects for roles", roles[0]);
const { subjects = [] } = await util.getRoleInfo(roles[0], req.log, req.id);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log message for getting subjects for roles has been removed. If this was intentional, ensure that the removal does not affect the debugging process. If not, consider reinstating it for better traceability.

const emailEventType = CONNECT_NOTIFICATION_EVENT.COPILOT_OPPORTUNITY_CREATED;
const emailEventType = CONNECT_NOTIFICATION_EVENT.EXTERNAL_ACTION_EMAIL;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change of emailEventType from CONNECT_NOTIFICATION_EVENT.COPILOT_OPPORTUNITY_CREATED to CONNECT_NOTIFICATION_EVENT.EXTERNAL_ACTION_EMAIL should be verified to ensure it aligns with the intended notification logic. This change might affect how the event is categorized or processed.

const copilotPortalUrl = config.get('copilotPortalUrl');
req.log.info("Sending emails to all copilots about new opportunity");
subjects.forEach(subject => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider handling the case where subjects might be an empty array to avoid unnecessary log entries or operations.

req.log.info("Each copilot members", subject);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log message 'Each copilot members' could be more descriptive. Consider including more context, such as the copilot's handle or email, to make the logs more informative.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log message for the copilot portal URL has been removed. If this was intentional, ensure that the removal does not affect the ability to trace the URL being used. If not, consider reinstating it for better traceability.

createEvent(emailEventType, {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log statement 'Each copilot members' was removed. If this was intentional, ensure that the logging is still sufficient for debugging purposes. If not, consider adding a relevant log statement to track each copilot being notified.

data: {
handle: subject.handle,
user_name: subject.handle,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key handle has been changed to user_name. Ensure that this change is compatible with the rest of the system and that any downstream dependencies are updated accordingly.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using camelCase for consistency with JavaScript naming conventions. Change user_name to userName.

opportunityDetailsUrl: `${copilotPortalUrl}/opportunity/${opportunity.id}`,
},
sendgrid_template_id: "d-3efdc91da580479d810c7acd50a4c17f",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The addition of sendgrid_template_id should be checked to confirm that the template ID d-3efdc91da580479d810c7acd50a4c17f is correct and that it exists in SendGrid. Also, verify that it matches the intended email format and content.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the template id to constant.

recipients: [subject.email],
version: 'v3',
from: {
name: config.get('EMAIL_INVITE_FROM_NAME'),
email: config.get('EMAIL_INVITE_FROM_EMAIL'),
},
categories: [`${process.env.NODE_ENV}:${emailEventType}`.toLowerCase()],
version: '433b1688-c543-4656-a295-efcbea57444d',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version field has been changed from 'v3' to '433b1688-c543-4656-a295-efcbea57444d'. Ensure that this version identifier is correct and that it corresponds to the expected versioning system or API.

}, req.log);
});

Expand Down