Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,36 @@ export function buildInteractiveBizNode(): BinaryNode {
};
}

/**
* Stanza nodes for the PIX button (`payment_info`).
*
* The generic `mixed` node above is enough for WhatsApp Web, but Android/iOS
* only render the payment card when the native_flow is named `payment_info`
* and, in 1:1 chats, when the stanza also carries `<bot biz_bot="1"/>`.
* Without them the message is delivered but nothing shows up on the phone.
*/
export function buildPixBizNodes(jid: string): BinaryNode[] {
const nodes: BinaryNode[] = [
{
tag: 'biz',
attrs: {},
content: [
{
tag: 'interactive',
attrs: { type: 'native_flow', v: '1' },
content: [{ tag: 'native_flow', attrs: { name: 'payment_info' } }],
},
],
},
];

if (!/@(g\.us|newsletter|broadcast)$/.test(jid)) {
nodes.push({ tag: 'bot', attrs: { biz_bot: '1' } });
}

return nodes;
}

/**
* Biz node especΓ­fico para `listMessage` legado.
* NecessΓ‘rio para o WhatsApp Web/Desktop renderizar a lista β€” o moderno
Expand Down
25 changes: 18 additions & 7 deletions src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ import { Label } from 'baileys/lib/Types/Label';
import { LabelAssociation } from 'baileys/lib/Types/LabelAssociation';
import { spawn } from 'child_process';
import { isArray, isBase64, isURL } from 'class-validator';
import { createHash } from 'crypto';
import { createHash, randomBytes } from 'crypto';
import EventEmitter2 from 'eventemitter2';
import ffmpeg from 'fluent-ffmpeg';
import FormData from 'form-data';
Expand All @@ -157,7 +157,12 @@ import { PassThrough, Readable } from 'stream';
import { v4 } from 'uuid';

import { BaileysMessageProcessor } from './baileysMessage.processor';
import { buildInteractiveBizNode, buildListBizNode, toNativeFlowButton } from './helpers/interactiveMessage.helper';
import {
buildInteractiveBizNode,
buildListBizNode,
buildPixBizNodes,
toNativeFlowButton,
} from './helpers/interactiveMessage.helper';
import { useVoiceCallsBaileys } from './voiceCalls/useVoiceCallsBaileys';

export interface ExtendedIMessageKey extends proto.IMessageKey {
Expand Down Expand Up @@ -3671,21 +3676,27 @@ export class BaileysStartupService extends ChannelStartupService {
throw new BadRequestException('PIX button cannot be mixed with other button types');
}

// Mobile clients need the `order_details` params, `messageVersion` and a
// `messageSecret` to render the payment card; WhatsApp Web renders it
// either way. Do NOT wrap it in `documentWithCaptionMessage`: mobile
// accepts the wrapper, but Web then shows nothing.
const message: proto.IMessage = {
interactiveMessage: {
...(data?.title ? { body: { text: data.title } } : {}),
nativeFlowMessage: {
buttons: [
{
name: this.mapType.get('pix'),
buttonParamsJson: this.toJSONString(data.buttons[0]),
},
],
messageParamsJson: JSON.stringify({
from: 'api',
templateId: v4(),
}),
messageParamsJson: JSON.stringify({ native_flow_name: 'order_details', version: 1 }),
messageVersion: 1,
},
},
messageContextInfo: {
messageSecret: randomBytes(32),
},
};

return await this.sendMessageWithTyping(
Expand All @@ -3699,7 +3710,7 @@ export class BaileysStartupService extends ChannelStartupService {
mentioned: data?.mentioned,
},
false,
[buildInteractiveBizNode()],
buildPixBizNodes(createJid(data.number)),
);
}

Expand Down