-
Notifications
You must be signed in to change notification settings - Fork 3.7k
improvement(sendblue): audit fixes — optional group numbers, seat_id, typing state/duration #5300
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
534b74e
improvement(sendblue): audit fixes — optional group numbers, seat_id,…
waleedlatif1 17bbe06
fix(sendblue): guard group recipients and typing state/duration befor…
waleedlatif1 116a0bb
fix(sendblue): omit empty numbers array from group message body
waleedlatif1 89d3885
test(sendblue): add webhook handler tests; trim group_id and normaliz…
waleedlatif1 bb4ccae
fix(sendblue): trim and drop blank group recipients before target guard
waleedlatif1 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
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
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,115 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| */ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { sendblueHandler } from '@/lib/webhooks/providers/sendblue' | ||
|
|
||
| const inboundBody = { | ||
| accountEmail: 'me@example.com', | ||
| content: 'hello', | ||
| media_url: '', | ||
| is_outbound: false, | ||
| status: 'RECEIVED', | ||
| message_handle: 'handle-123', | ||
| from_number: '+19998887777', | ||
| number: '+18887776666', | ||
| group_id: '', | ||
| } | ||
|
|
||
| const outboundBody = { | ||
| ...inboundBody, | ||
| is_outbound: true, | ||
| status: 'SENT', | ||
| } | ||
|
|
||
| describe('sendblueHandler', () => { | ||
| describe('matchEvent', () => { | ||
| it('matches an inbound message for the message_received trigger', () => { | ||
| expect( | ||
| sendblueHandler.matchEvent!({ | ||
| body: inboundBody, | ||
| webhook: { providerConfig: { triggerId: 'sendblue_message_received' } }, | ||
| requestId: 'r1', | ||
| } as any) | ||
| ).toBe(true) | ||
| }) | ||
|
|
||
| it('rejects an outbound event for the message_received trigger', () => { | ||
| expect( | ||
| sendblueHandler.matchEvent!({ | ||
| body: outboundBody, | ||
| webhook: { providerConfig: { triggerId: 'sendblue_message_received' } }, | ||
| requestId: 'r1', | ||
| } as any) | ||
| ).toBe(false) | ||
| }) | ||
|
|
||
| it('matches an outbound status update for the message_status_updated trigger', () => { | ||
| expect( | ||
| sendblueHandler.matchEvent!({ | ||
| body: outboundBody, | ||
| webhook: { providerConfig: { triggerId: 'sendblue_message_status_updated' } }, | ||
| requestId: 'r1', | ||
| } as any) | ||
| ).toBe(true) | ||
| }) | ||
|
|
||
| it('passes through when the triggerId is unknown or unset', () => { | ||
| expect( | ||
| sendblueHandler.matchEvent!({ | ||
| body: inboundBody, | ||
| webhook: {}, | ||
| requestId: 'r1', | ||
| } as any) | ||
| ).toBe(true) | ||
| }) | ||
|
|
||
| it('rejects a non-object payload for a known trigger', () => { | ||
| expect( | ||
| sendblueHandler.matchEvent!({ | ||
| body: 'not-an-object', | ||
| webhook: { providerConfig: { triggerId: 'sendblue_message_received' } }, | ||
| requestId: 'r1', | ||
| } as any) | ||
| ).toBe(false) | ||
| }) | ||
| }) | ||
|
|
||
| describe('extractIdempotencyId', () => { | ||
| it('uses the message handle alone when no status is present', () => { | ||
| expect(sendblueHandler.extractIdempotencyId!({ message_handle: 'handle-123' })).toBe( | ||
| 'handle-123' | ||
| ) | ||
| }) | ||
|
|
||
| it('suffixes the status so SENT and DELIVERED on one handle stay distinct', () => { | ||
| expect( | ||
| sendblueHandler.extractIdempotencyId!({ message_handle: 'handle-123', status: 'DELIVERED' }) | ||
| ).toBe('handle-123:DELIVERED') | ||
| }) | ||
|
|
||
| it('returns null when no message handle is present', () => { | ||
| expect(sendblueHandler.extractIdempotencyId!({})).toBeNull() | ||
| expect(sendblueHandler.extractIdempotencyId!('nope')).toBeNull() | ||
| }) | ||
| }) | ||
|
|
||
| describe('formatInput', () => { | ||
| it('returns the payload under input with empty strings normalized to null', async () => { | ||
| const result = await sendblueHandler.formatInput!({ body: inboundBody } as any) | ||
| expect(result.input.account_email).toBe('me@example.com') | ||
| expect(result.input.media_url).toBeNull() | ||
| expect(result.input.group_id).toBeNull() | ||
| expect(result.input.is_outbound).toBe(false) | ||
| expect(result.input.participants).toEqual([]) | ||
| expect(result.input.raw).toBe(JSON.stringify(inboundBody)) | ||
| }) | ||
|
|
||
| it('defaults missing fields to null and tolerates a non-object body', async () => { | ||
| const result = await sendblueHandler.formatInput!({ body: undefined } as any) | ||
| expect(result.input.message_handle).toBeNull() | ||
| expect(result.input.content).toBeNull() | ||
| expect(result.input.participants).toEqual([]) | ||
| }) | ||
| }) | ||
| }) |
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.
Uh oh!
There was an error while loading. Please reload this page.