Skip to content
Merged
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
448 changes: 448 additions & 0 deletions manager/dist/assets/test-interactive.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions manager/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
</head>
<body>
<div id="root"></div>
<script src="/assets/test-interactive.js" defer></script>
</body>
</html>
4 changes: 3 additions & 1 deletion src/api/controllers/instance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,10 @@ export class InstanceController {
public async logout({ instanceName }: InstanceDto) {
const { instance } = await this.connectionState({ instanceName });

// Idempotente: se já está desconectada, retorna sucesso silenciosamente.
// Evita falhar o fluxo de delete do painel, que sempre chama logout antes do delete.
if (instance.state === 'close') {
throw new BadRequestException('The "' + instanceName + '" instance is not connected');
return { status: 'SUCCESS', error: false, response: { message: 'Instance was already disconnected' } };
}

try {
Expand Down
5 changes: 5 additions & 0 deletions src/api/controllers/sendMessage.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { InstanceDto } from '@api/dto/instance.dto';
import {
SendAudioDto,
SendButtonsDto,
SendCarouselDto,
SendContactDto,
SendListDto,
SendLocationDto,
Expand Down Expand Up @@ -86,6 +87,10 @@ export class SendMessageController {
return await this.waMonitor.waInstances[instanceName].listMessage(data);
}

public async sendCarousel({ instanceName }: InstanceDto, data: SendCarouselDto) {
return await this.waMonitor.waInstances[instanceName].carouselMessage(data);
}

public async sendContact({ instanceName }: InstanceDto, data: SendContactDto) {
return await this.waMonitor.waInstances[instanceName].contactMessage(data);
}
Expand Down
13 changes: 13 additions & 0 deletions src/api/dto/sendMessage.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,16 @@ export class SendReactionDto {
key: proto.IMessageKey;
reaction: string;
}

export class CarouselCard {
title?: string;
body: string;
footer?: string;
imageUrl?: string;
buttons: Button[];
}

export class SendCarouselDto extends Metadata {
body: string;
cards: CarouselCard[];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import { Button, KeyType } from '@api/dto/sendMessage.dto';
import { BinaryNode } from 'baileys';

export function buildInteractiveBizNode(): BinaryNode {
return {
tag: 'biz',
attrs: {},
content: [
{
tag: 'interactive',
attrs: { type: 'native_flow', v: '1' },
content: [{ tag: 'native_flow', attrs: { v: '9', name: 'mixed' } }],
},
],
};
}

/**
* Biz node específico para `listMessage` legado.
* Necessário para o WhatsApp Web/Desktop renderizar a lista — o moderno
* (`interactiveMessage` + `single_select`) não é renderizado no Web.
*/
export function buildListBizNode(): BinaryNode {
return {
tag: 'biz',
attrs: {},
content: [{ tag: 'list', attrs: { type: 'product_list', v: '2' } }],
};
}

type NativeFlowButton = { name: string; buttonParamsJson: string };

type NativeFlowDeps = {
generateRandomId: () => string;
mapKeyType: Map<KeyType, string>;
};

export function toNativeFlowButton(button: Button, deps: NativeFlowDeps): NativeFlowButton {
const displayText = button.displayText ?? '';

switch (button.type) {
case 'url':
return {
name: 'cta_url',
buttonParamsJson: JSON.stringify({
display_text: displayText,
url: button.url,
merchant_url: button.url,
}),
};

case 'call':
return {
name: 'cta_call',
buttonParamsJson: JSON.stringify({
display_text: displayText,
phone_number: button.phoneNumber,
}),
};

case 'copy':
return {
name: 'cta_copy',
buttonParamsJson: JSON.stringify({
display_text: displayText,
copy_code: button.copyCode,
}),
};

case 'reply':
return {
name: 'quick_reply',
buttonParamsJson: JSON.stringify({
display_text: displayText,
id: button.id ?? deps.generateRandomId(),
}),
};

case 'pix':
return {
name: 'payment_info',
buttonParamsJson: JSON.stringify({
currency: button.currency,
total_amount: { value: 0, offset: 100 },
reference_id: deps.generateRandomId(),
type: 'physical-goods',
order: {
status: 'pending',
subtotal: { value: 0, offset: 100 },
order_type: 'ORDER',
items: [
{ name: '', amount: { value: 0, offset: 100 }, quantity: 0, sale_amount: { value: 0, offset: 100 } },
],
},
payment_settings: [
{
type: 'pix_static_code',
pix_static_code: {
merchant_name: button.name,
key: button.key,
key_type: deps.mapKeyType.get(button.keyType),
},
},
],
share_payment_status: false,
}),
};

default:
throw new Error(`Unsupported button type: ${(button as Button).type}`);
}
}

type ListSection = {
title: string;
rows: Array<{ title: string; description?: string; rowId: string }>;
};

export function buildSingleSelectButton(buttonText: string, sections: ListSection[]): NativeFlowButton {
const buttonParams = {
title: buttonText || ' ',
sections: (sections || []).map((section) => ({
title: section.title || ' ',
highlight_label: '',
rows: (section.rows || []).map((row, index) => {
const rowTitle = row.title || ' ';
return {
header: rowTitle,
title: rowTitle,
description: row.description || ' ',
id: row.rowId || `row_${index}`,
};
}),
})),
};

return {
name: 'single_select',
buttonParamsJson: JSON.stringify(buttonParams),
};
}
Loading
Loading