Skip to content
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: WhatsApp Business Cloud Node - new operation sendAndWait #12941

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

michael-radency
Copy link
Contributor

Summary

New operation sendAndWait
declarativeRunExceptions for declarative nodes

Related Linear tickets, Github issues, and Community forum posts

https://linear.app/n8n/issue/NODE-2296/whatsapp-sendandwait-operation

@michael-radency michael-radency added node/improvement New feature or request n8n team Authored by the n8n team node/issue Issue with a node labels Jan 30, 2025
Copy link

codecov bot commented Jan 30, 2025

Codecov Report

Attention: Patch coverage is 79.41176% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ages/core/src/execution-engine/workflow-execute.ts 58.33% 3 Missing and 2 partials ⚠️
...ackages/nodes-base/nodes/WhatsApp/WhatsApp.node.ts 95.00% 1 Missing ⚠️
.../nodes-base/nodes/WhatsApp/WhatsAppTrigger.node.ts 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@dana-gill dana-gill requested a review from elsmr January 30, 2025 13:26
Copy link
Member

@elsmr elsmr left a comment

Choose a reason for hiding this comment

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

Whatsapp sendAndWait functionality works as expected 🎉 , not sure about the DeclarativeRunException implementation.

},
declarativeRunExceptions: [
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to instead fall back to execute when a resource/operation has no routing info?

@michael-radency michael-radency requested review from elsmr and ivov January 31, 2025 12:31
} else if (nodeType.webhook && !nodeType.description.requestDefaults) {
// Check if the node have requestDefaults(RoutingNode),
// else for webhook nodes always simply pass the data through
// as webhook method would be called by WebhookService
return { data: inputData.main as INodeExecutionData[][] };
} else {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ivov
having RoutingNode as a fallback seems to be wrong, should webhook branch be the last one or having return { data: inputData.main as INodeExecutionData[][] }; in else branch?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't quite follow you here, let's discuss tomorrow!

@@ -1643,6 +1643,13 @@ export interface INodeType {
[method in WebhookSetupMethodNames]: (this: IHookFunctions) => Promise<boolean>;
};
};
nonRoutingOperations?: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Naming-wise I prefer to avoid negatives, plus they're still inside the routing node. What about customOperations with a docline on top explaining what this is?

[resource: string]: {
[operation: string]: (
context: IExecuteFunctions,
) => Promise<INodeExecutionData[][] | NodeExecutionWithMetadata[][] | null>;
Copy link
Contributor

Choose a reason for hiding this comment

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

This type is repeated and a bit obscure. Would it be clearer to have and use type NodeOutput = INodeExecutionData[][] | NodeExecutionWithMetadata[][] | null?

const operation = context.getNodeParameter('operation', 0) as string;
const returnData: INodeExecutionData[] = [];

if (resource === 'message' && operation === SEND_AND_WAIT_OPERATION) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we have resource and operation on the key and function name, and also inside the function body. Can we simplify by having this function be specific to the resource + operation pair that's already specified?

@@ -986,6 +989,21 @@ export class WorkflowExecute {
return workflowIssues;
}

private getRoutingNodeExecuteFunction(node: INode, type: INodeType) {
Copy link
Contributor

@ivov ivov Feb 10, 2025

Choose a reason for hiding this comment

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

Suggested change
private getRoutingNodeExecuteFunction(node: INode, type: INodeType) {
private getCustomOperation(node: INode, type: INodeType) {

Comment on lines 999 to 1001
return type.nonRoutingOperations[resource][operation] as (
context: IExecuteFunctions,
) => Promise<INodeExecutionData[][] | NodeExecutionWithMetadata[][] | null>;
Copy link
Contributor

@ivov ivov Feb 10, 2025

Choose a reason for hiding this comment

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

Can we dig into why we need to assert the type here? This was already typed in the workflow package.

Also another option:

private getCustomOperation(node: INode, type: INodeType) {
    const { resource, operation } = node.parameters;

    if (typeof resource !== 'string' || typeof operation !== 'string') return;

    return type.nonRoutingOperations?.[resource]?.[operation];
}

let connectionInputData: INodeExecutionData[] = [];
if (nodeType.execute || (!nodeType.poll && !nodeType.trigger && !nodeType.webhook)) {
if (
nodeType.execute ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it simplify the implementation if we override nodeType.execute with this custom function?

Copy link
Contributor Author

@michael-radency michael-radency Feb 12, 2025

Choose a reason for hiding this comment

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

we could not do that, it will causes issue for other node's operations

@michael-radency michael-radency changed the title feat(WhatsApp Business Cloud Node): New operation sendAndWait feat: WhatsApp Business Cloud Node - new operation sendAndWait Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
n8n team Authored by the n8n team node/improvement New feature or request node/issue Issue with a node
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants