mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
feat: Add appendN8nAttribution option to sendAndWait operation (#13697)
Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
@@ -15,6 +15,7 @@ import type {
|
||||
WhatsAppAppWebhookSubscription,
|
||||
} from './types';
|
||||
import type { SendAndWaitConfig } from '../../utils/sendAndWait/utils';
|
||||
import { createUtmCampaignLink } from '../../utils/utilities';
|
||||
export const WHATSAPP_BASE_URL = 'https://graph.facebook.com/v13.0/';
|
||||
|
||||
async function appAccessTokenRead(
|
||||
@@ -109,11 +110,19 @@ export const createMessage = (
|
||||
sendAndWaitConfig: SendAndWaitConfig,
|
||||
phoneNumberId: string,
|
||||
recipientPhoneNumber: string,
|
||||
instanceId: string,
|
||||
): IHttpRequestOptions => {
|
||||
const buttons = sendAndWaitConfig.options.map((option) => {
|
||||
return `*${option.label}:*\n_${sendAndWaitConfig.url}?approved=${option.value}_\n\n`;
|
||||
});
|
||||
|
||||
let n8nAttribution: string = '';
|
||||
if (sendAndWaitConfig.appendAttribution) {
|
||||
const attributionText = 'This message was sent automatically with ';
|
||||
const link = createUtmCampaignLink('n8n-nodes-base.whatsapp', instanceId);
|
||||
n8nAttribution = `\n\n${attributionText}${link}`;
|
||||
}
|
||||
|
||||
return {
|
||||
baseURL: WHATSAPP_BASE_URL,
|
||||
method: 'POST',
|
||||
@@ -121,7 +130,7 @@ export const createMessage = (
|
||||
body: {
|
||||
messaging_product: 'whatsapp',
|
||||
text: {
|
||||
body: `${sendAndWaitConfig.message}\n\n${buttons.join('')}`,
|
||||
body: `${sendAndWaitConfig.message}\n\n${buttons.join('')}${n8nAttribution}`,
|
||||
},
|
||||
type: 'text',
|
||||
to: recipientPhoneNumber,
|
||||
|
||||
@@ -83,11 +83,12 @@ export class WhatsApp implements INodeType {
|
||||
);
|
||||
|
||||
const config = getSendAndWaitConfig(this);
|
||||
const instanceId = this.getInstanceId();
|
||||
|
||||
await this.helpers.httpRequestWithAuthentication.call(
|
||||
this,
|
||||
WHATSAPP_CREDENTIALS_TYPE,
|
||||
createMessage(config, phoneNumberId, recipientPhoneNumber),
|
||||
createMessage(config, phoneNumberId, recipientPhoneNumber, instanceId),
|
||||
);
|
||||
|
||||
const waitTill = configureWaitTillDate(this);
|
||||
|
||||
@@ -43,6 +43,7 @@ describe('createMessage', () => {
|
||||
mockSendAndWaitConfig,
|
||||
phoneID,
|
||||
recipientPhone,
|
||||
'',
|
||||
);
|
||||
|
||||
expect(request).toEqual({
|
||||
@@ -77,7 +78,12 @@ describe('createMessage', () => {
|
||||
],
|
||||
};
|
||||
|
||||
const request: IHttpRequestOptions = createMessage(singleOptionConfig, phoneID, recipientPhone);
|
||||
const request: IHttpRequestOptions = createMessage(
|
||||
singleOptionConfig,
|
||||
phoneID,
|
||||
recipientPhone,
|
||||
'',
|
||||
);
|
||||
|
||||
expect(request).toEqual({
|
||||
baseURL: WHATSAPP_BASE_URL,
|
||||
|
||||
Reference in New Issue
Block a user