-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat(api-service): add Gmail email reactions #10860
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e3824bf
Add support for email MIME alternatives
scopsy 2c615de
Update chat-sdk.service.ts
scopsy af541dc
Update adapter.ts
scopsy df3abce
Handle email reactions and MIME alternatives
scopsy cd6b5a6
Merge branch 'next' into feat-add-email-reactions
scopsy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
119 changes: 119 additions & 0 deletions
119
apps/api/src/app/agents/services/chat-sdk.service.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| import { ChannelTypeEnum, EmailProviderIdEnum } from '@novu/shared'; | ||
| import { expect } from 'chai'; | ||
| import sinon from 'sinon'; | ||
| import { ChatSdkService } from './chat-sdk.service'; | ||
|
|
||
| describe('ChatSdkService', () => { | ||
| describe('buildSendEmailCallback', () => { | ||
| it('should skip custom MIME alternatives for unsupported outbound providers', async () => { | ||
| const logger = { | ||
| warn: sinon.stub(), | ||
| error: sinon.stub(), | ||
| debug: sinon.stub(), | ||
| info: sinon.stub(), | ||
| }; | ||
| const integrationRepository = { | ||
| findOne: sinon.stub().resolves({ | ||
| _id: 'outbound-integration-id', | ||
| _environmentId: 'env-id', | ||
| _organizationId: 'org-id', | ||
| providerId: EmailProviderIdEnum.Resend, | ||
| channel: ChannelTypeEnum.EMAIL, | ||
| credentials: {}, | ||
| active: true, | ||
| }), | ||
| }; | ||
| const service = new ChatSdkService(logger as any, {} as any, {} as any, {} as any, integrationRepository as any); | ||
| const sendEmail = (service as any).buildSendEmailCallback( | ||
| { | ||
| environmentId: 'env-id', | ||
| organizationId: 'org-id', | ||
| credentials: {}, | ||
| }, | ||
| 'outbound-integration-id' | ||
| ); | ||
|
|
||
| const result = await sendEmail({ | ||
| from: 'agent@example.com', | ||
| to: 'user@gmail.com', | ||
| subject: 'Re: Hello', | ||
| text: '👀', | ||
| html: '<p>👀</p>', | ||
| alternatives: [ | ||
| { | ||
| contentType: 'text/vnd.google.email-reaction+json', | ||
| content: JSON.stringify({ version: 1, emoji: '👀' }), | ||
| }, | ||
| ], | ||
| messageId: '<reaction@example.com>', | ||
| inReplyTo: '<original@example.com>', | ||
| references: '<original@example.com>', | ||
| }); | ||
|
|
||
| expect(result).to.deep.equal({ messageId: '<reaction@example.com>' }); | ||
| expect(logger.warn.calledOnce).to.equal(true); | ||
| expect(logger.warn.firstCall.args[0]).to.deep.equal({ | ||
| providerId: EmailProviderIdEnum.Resend, | ||
| outboundIntegrationId: 'outbound-integration-id', | ||
| }); | ||
| expect(logger.warn.firstCall.args[1]).to.include('does not support custom MIME alternatives'); | ||
| expect( | ||
| integrationRepository.findOne.calledOnceWithMatch({ | ||
| _id: 'outbound-integration-id', | ||
| channel: ChannelTypeEnum.EMAIL, | ||
| }) | ||
| ).to.equal(true); | ||
| }); | ||
|
|
||
| it('should not claim success when unsupported MIME alternatives omit messageId', async () => { | ||
| const logger = { | ||
| warn: sinon.stub(), | ||
| error: sinon.stub(), | ||
| debug: sinon.stub(), | ||
| info: sinon.stub(), | ||
| }; | ||
| const integrationRepository = { | ||
| findOne: sinon.stub().resolves({ | ||
| _id: 'outbound-integration-id', | ||
| _environmentId: 'env-id', | ||
| _organizationId: 'org-id', | ||
| providerId: EmailProviderIdEnum.Resend, | ||
| channel: ChannelTypeEnum.EMAIL, | ||
| credentials: {}, | ||
| active: true, | ||
| }), | ||
| }; | ||
| const service = new ChatSdkService(logger as any, {} as any, {} as any, {} as any, integrationRepository as any); | ||
| const sendEmail = (service as any).buildSendEmailCallback( | ||
| { | ||
| environmentId: 'env-id', | ||
| organizationId: 'org-id', | ||
| credentials: {}, | ||
| }, | ||
| 'outbound-integration-id' | ||
| ); | ||
|
|
||
| const result = await sendEmail({ | ||
| from: 'agent@example.com', | ||
| to: 'user@gmail.com', | ||
| subject: 'Re: Hello', | ||
| text: '👀', | ||
| html: '<p>👀</p>', | ||
| alternatives: [ | ||
| { | ||
| contentType: 'text/vnd.google.email-reaction+json', | ||
| content: JSON.stringify({ version: 1, emoji: '👀' }), | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| expect(result).to.deep.equal({ messageId: undefined }); | ||
| expect(logger.warn.calledOnce).to.equal(true); | ||
| expect(logger.warn.firstCall.args[0]).to.deep.equal({ | ||
| providerId: EmailProviderIdEnum.Resend, | ||
| outboundIntegrationId: 'outbound-integration-id', | ||
| }); | ||
| expect(logger.warn.firstCall.args[1]).to.include('no messageId was supplied'); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor:
'New message'is an odd subject for a reaction.A reaction should be threaded against a prior inbound message, so
storedSubjectshould always be populated by the timeaddReactionruns. If it isn't, falling back to'New message'will produce a reaction email with a generic subject and rely solely onIn-Reply-To/Referencesfor threading — which Gmail will mostly handle, but the visible subject in the recipient's client will be misleading. Consider either dropping the reaction (consistent with the other silent no-op paths in this method) or logging a warning so the missing-subject case is observable.🤖 Prompt for AI Agents