Send Email Notification on Chatbot Answer Change#421
Send Email Notification on Chatbot Answer Change#421ribhavsharma wants to merge 12 commits intomainfrom
Conversation
...)/course/[cid]/(settings)/settings/chatbot_questions/components/EditChatbotQuestionModal.tsx
Outdated
Show resolved
Hide resolved
| <br/> | ||
| <p>You can revisit the course chatbot from your course page.</p> | ||
| </div> | ||
| `; |
There was a problem hiding this comment.
Most of the body of this endpoint should be moved into its own method inside chatbot.service.ts since controllers are technically supposed to just handle like error checking and then calling the right services, and thus are supposed to be pretty slim.
| ChatbotService, | ||
| ChatbotApiService, | ||
| ChatbotSettingsSubscriber, | ||
| MailService, |
There was a problem hiding this comment.
huh interesting, i guess you didn't need to add MailModule to the imports array for some reason?
| TestTypeOrmModule, | ||
| TestConfigModule, | ||
| FactoryModule, | ||
| ChatbotModule.forRoot(TestChatbotConnectionOptions), |
There was a problem hiding this comment.
wait... what?
I didn't really touch the lms stuff but i feel like removing the chatbotmodule would break tests but idk. @bhunt02
...)/course/[cid]/(settings)/settings/chatbot_questions/components/EditChatbotQuestionModal.tsx
Outdated
Show resolved
Hide resolved
...)/course/[cid]/(settings)/settings/chatbot_questions/components/EditChatbotQuestionModal.tsx
Outdated
Show resolved
Hide resolved
...)/course/[cid]/(settings)/settings/chatbot_questions/components/EditChatbotQuestionModal.tsx
Show resolved
Hide resolved
|
Oh right, and maybe adding a handful of integration or service tests for this would be a pretty good idea! |
…comment explaining why we limit the number of recpients
AdamFipke
left a comment
There was a problem hiding this comment.
Thanks for addressing the feedback. I also manually tested it and it seems to work! Going over it I commited a couple small things.
Main things are some comments about tests. The feedback there could also be applied to your other PRs.
I would still see about moving most of the method body of notifyUpdatedAnswer() endpoint into its own function inside chatbot.service.ts for organization reasons.
| const { emailNotifyOnAnswerUpdate, ...sanitizedValues } = values | ||
| const valuesWithId = { | ||
| ...values, | ||
| ...sanitizedValues, |
There was a problem hiding this comment.
Huh neat I didn't know you could use the spread operator when deconstructing an object
| }); | ||
| }); | ||
|
|
||
| describe('POST /chatbot/question/:courseId/:vectorStoreId/notify', () => { |
There was a problem hiding this comment.
I would possibly add a few more tests for:
- Making sure only professors and TAs can use it
- Making sure it only notifies students who asked the question, not other students in the course.
- Make sure it still succeeds for empty strings for old and new answer
- Tests to make sure the DTO is working:
- Making sure it fails if oldAnswer is undefined
- Making sure it fails if newAnswer is undefined
- Make sure you can't send integers or other data types for oldAnswer, newAnswer, oldQuestion, and newQuestion
You may also find it nicer to refactor a bunch of your tests into helper functions (you can see an example in @bhunt02 's PR here https://github.com/ubco-db/helpme/pull/351/files#diff-8d3cece12bb8c1d5223de78a3e45bee5b3becbb4dfef50609332fac922bebd6cR737.
You can probably just get away with using AI to generate these (just use a smart model like gemeni 3 pro or opus/sonnet 4.5) and make sure to go over it so there's no glaring logic issues.
It would also be nice if there was a test to make sure the email didn't have "null" or stuff like that, but that might be a little more effort than it's worth (since it might involve modifying the email test util functions and saving a snapshot). Maybe look into it?
| import { BadRequestException } from '@nestjs/common'; | ||
| import { NotifyUpdatedChatbotAnswerParams, Role } from '@koh/common'; | ||
|
|
||
| describe('ChatbotController - notifyUpdatedAnswer', () => { |
There was a problem hiding this comment.
So this is kinda weird. This is like an integration test but with a few more details abstracted away, and it doesn't really follow the rest of the project.
Having just the chatbot.integration.ts tests are enough (since that tests calling the whole endpoint). Once you move most of the body of the notifyUpdatedAnswer to its own function inside chatbot.service.ts, you could make some corresponding unit tests inside chatbot.service.spec.ts, but it's usually not necessary since the integration tests already cover it. Though, having unit tests may be nicer if you want to test for very specific behaviour by mocking a bunch of things (e.g. for making sure the email body is correct).
There was a problem hiding this comment.
I think chatbot.service.ts does a lot of jobs already... should the FX for notifying not be delegated to a corresponding proviser?
There was a problem hiding this comment.
I think chatbot.service.ts does a lot of jobs already... should the FX for notifying not be delegated to a corresponding proviser?
Hmm maybe. Are you thinking a small-scoped provider (e.g. chatbot-email-notification.service.ts) or larger provider (e.g. notification-email.service.ts)?
Though I don't see us adding many more email notifications to do with the chatbot. And a larger one wouldn't make much sense imo since then it's a big random service file that gets imported to a bunch of other files for only 1 function.
If we're concerned about the size of chatbot.service.ts, it woudl probably make more sense to refactor out the ChatbotOrganizationSettings (or just ChatbotSettings) stuff into its own service.
There was a problem hiding this comment.
No what I mean is single responsibility principle. Notifications should be handled by one provider, not many
All the chatbot stuff falls under the purview of the chatbot provider
Description
Added a checkbox in the edit chatbot answer modal, that lets the professor send out notifications to relevant students when a chatbot answer is changed.
Closes #305
Type of change
yarn installHow Has This Been Tested?
Tested locally, the correct email shows up in the "sent emails" log file.
Checklist:
console.logs, leftover unused logic, or anything else that was accidentally committed)