-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
feat(Discord Node): New sendAndWait operation #12894
Merged
michael-radency
merged 15 commits into
master
from
node-2325-discord-sendandwait-operation
Jan 31, 2025
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f68835b
setup
michael-radency 2384a79
Merge branch 'master' of https://github.com/n8n-io/n8n into node-2325…
michael-radency 5d3fe7e
Merge branch 'master' of https://github.com/n8n-io/n8n into node-2325…
michael-radency c9a913d
tests
michael-radency 3d4fb8d
Merge branch 'master' of https://github.com/n8n-io/n8n into node-2325…
michael-radency 611dc11
alias update
michael-radency d9ba6fa
Merge branch 'master' of https://github.com/n8n-io/n8n into node-2325…
michael-radency a151ef0
Merge branch 'master' of https://github.com/n8n-io/n8n into node-2325…
michael-radency e96be05
codex update
michael-radency 8de8973
Merge branch 'master' of https://github.com/n8n-io/n8n into node-2325…
michael-radency a157c3a
Update packages/nodes-base/nodes/Discord/v2/helpers/utils.ts
michael-radency e00d2f3
import fix
michael-radency 26cf0e2
Merge branch 'master' into node-2325-discord-sendandwait-operation
michael-radency c507e81
Merge branch 'master' of https://github.com/n8n-io/n8n into node-2325…
michael-radency 3d8e8e8
Merge branch 'node-2325-discord-sendandwait-operation' of https://git…
michael-radency 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
93 changes: 93 additions & 0 deletions
93
packages/nodes-base/nodes/Discord/test/v2/node/message/sendAndWait.test.ts
This file contains 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,93 @@ | ||
import type { MockProxy } from 'jest-mock-extended'; | ||
import { mock } from 'jest-mock-extended'; | ||
import { SEND_AND_WAIT_OPERATION, type IExecuteFunctions } from 'n8n-workflow'; | ||
|
||
import { versionDescription } from '../../../../v2/actions/versionDescription'; | ||
import { DiscordV2 } from '../../../../v2/DiscordV2.node'; | ||
import * as transport from '../../../../v2/transport/discord.api'; | ||
|
||
jest.mock('../../../../v2/transport/discord.api', () => { | ||
const originalModule = jest.requireActual('../../../../v2/transport/discord.api'); | ||
return { | ||
...originalModule, | ||
discordApiRequest: jest.fn(async function (method: string) { | ||
if (method === 'POST') { | ||
return {}; | ||
} | ||
}), | ||
}; | ||
}); | ||
|
||
describe('Test DiscordV2, message => sendAndWait', () => { | ||
let discord: DiscordV2; | ||
let mockExecuteFunctions: MockProxy<IExecuteFunctions>; | ||
|
||
beforeEach(() => { | ||
discord = new DiscordV2(versionDescription); | ||
mockExecuteFunctions = mock<IExecuteFunctions>(); | ||
mockExecuteFunctions.helpers = { | ||
constructExecutionMetaData: jest.fn(() => []), | ||
returnJsonArray: jest.fn(() => []), | ||
} as any; | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should send message and put execution to wait', async () => { | ||
const items = [{ json: { data: 'test' } }]; | ||
mockExecuteFunctions.getNodeParameter.mockImplementation((key: string) => { | ||
if (key === 'operation') return SEND_AND_WAIT_OPERATION; | ||
if (key === 'resource') return 'message'; | ||
if (key === 'authentication') return 'botToken'; | ||
if (key === 'message') return 'my message'; | ||
if (key === 'subject') return ''; | ||
if (key === 'approvalOptions.values') return {}; | ||
if (key === 'responseType') return 'approval'; | ||
if (key === 'sendTo') return 'channel'; | ||
if (key === 'channelId') return 'channelID'; | ||
if (key === 'options.limitWaitTime.values') return {}; | ||
}); | ||
|
||
mockExecuteFunctions.putExecutionToWait.mockImplementation(); | ||
mockExecuteFunctions.getInputData.mockReturnValue(items); | ||
mockExecuteFunctions.getInstanceId.mockReturnValue('instanceId'); | ||
|
||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('http://localhost/waiting-webhook'); | ||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('nodeID'); | ||
|
||
const result = await discord.execute.call(mockExecuteFunctions); | ||
|
||
expect(result).toEqual([items]); | ||
expect(transport.discordApiRequest).toHaveBeenCalledTimes(1); | ||
expect(mockExecuteFunctions.putExecutionToWait).toHaveBeenCalledTimes(1); | ||
|
||
expect(transport.discordApiRequest).toHaveBeenCalledWith( | ||
'POST', | ||
'/channels/channelID/messages', | ||
{ | ||
components: [ | ||
{ | ||
components: [ | ||
{ | ||
label: 'Approve', | ||
style: 5, | ||
type: 2, | ||
url: 'http://localhost/waiting-webhook/nodeID?approved=true', | ||
}, | ||
], | ||
type: 1, | ||
}, | ||
], | ||
embeds: [ | ||
{ | ||
color: 5814783, | ||
description: | ||
'my message\n\n_This message was sent automatically with _[n8n](https://n8n.io/?utm_source=n8n-internal&utm_medium=powered_by&utm_campaign=n8n-nodes-base.telegram_instanceId)', | ||
}, | ||
], | ||
}, | ||
); | ||
}); | ||
}); |
This file contains 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
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.
I might be using this wrong -- when I tried to configure this on Discord, I don't get a Decline option
![Screenshot 2025-01-29 at 16 31 59](https://private-user-images.githubusercontent.com/152518854/407797514-1be41ccc-33d8-453a-8246-a01730aac3ae.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzNDU3NzYsIm5iZiI6MTczOTM0NTQ3NiwicGF0aCI6Ii8xNTI1MTg4NTQvNDA3Nzk3NTE0LTFiZTQxY2NjLTMzZDgtNDUzYS04MjQ2LWEwMTczMGFhYzNhZS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjEyJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxMlQwNzMxMTZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1hNjI0OWJiYzkyZTM0YTc5NDNiM2FhZWYzMjg0OGYyZDRhMzU1NmM1YjAxYjliNGM4MzVhNjkyMDU5NTE5NWM4JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.5E_QWxIyFqtt4hHSePe-zRkkAzgsulHXfVcJSoLhweU)
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.
@dana-gill
![image](https://private-user-images.githubusercontent.com/88898367/408050436-80846f34-76ec-4f86-9584-cbc24b3ce1d5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzNDU3NzYsIm5iZiI6MTczOTM0NTQ3NiwicGF0aCI6Ii84ODg5ODM2Ny80MDgwNTA0MzYtODA4NDZmMzQtNzZlYy00Zjg2LTk1ODQtY2JjMjRiM2NlMWQ1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEyVDA3MzExNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWUyZjlhMmUxMzU1YzJhYzE4NWRmNWU4YzQ5ZTdhMjI2YWVmYzdkZWJiMDQ3NDJlZmIzMjNmOTI2MWYxOThhMzEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.S4Cpzq9FyIIyTAcQdeofRxUWGj4JHQWEZSieMIGeH5o)
by default message send with one button option, you need to chose corresponding Approval option