Skip to content

Commit a4f8e95

Browse files
chore(lint): fix formatting and remove stray text
1 parent 08f8d05 commit a4f8e95

File tree

1 file changed

+102
-106
lines changed

1 file changed

+102
-106
lines changed

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 102 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -3310,53 +3310,121 @@ export class BaileysStartupService extends ChannelStartupService {
33103310
['random', 'EVP'],
33113311
]);
33123312

3313-
aqui?
3314-
3315-
public async buttonMessage(data: SendButtonsDto) {
3316-
if (!data.buttons || data.buttons.length === 0) {
3317-
throw new BadRequestException('At least one button is required');
3318-
}
3313+
public async buttonMessage(data: SendButtonsDto) {
3314+
if (!data.buttons || data.buttons.length === 0) {
3315+
throw new BadRequestException('At least one button is required');
3316+
}
33193317

3320-
const hasReplyButtons = data.buttons.some((btn) => btn.type === 'reply');
3321-
const hasPixButton = data.buttons.some((btn) => btn.type === 'pix');
3322-
const hasCTAButtons = data.buttons.some(
3323-
(btn) => btn.type === 'url' || btn.type === 'call' || btn.type === 'copy',
3324-
);
3318+
const hasReplyButtons = data.buttons.some((btn) => btn.type === 'reply');
3319+
const hasPixButton = data.buttons.some((btn) => btn.type === 'pix');
3320+
const hasCTAButtons = data.buttons.some((btn) => btn.type === 'url' || btn.type === 'call' || btn.type === 'copy');
33253321

3326-
/* =========================
3327-
* REGRAS DE VALIDAÇÃO
3328-
* ========================= */
3322+
/* =========================
3323+
* REGRAS DE VALIDAÇÃO
3324+
* ========================= */
33293325

3330-
// Reply
3331-
if (hasReplyButtons) {
3332-
if (data.buttons.length > 3) {
3333-
throw new BadRequestException('Maximum of 3 reply buttons allowed');
3334-
}
3335-
if (hasCTAButtons || hasPixButton) {
3336-
throw new BadRequestException('Reply buttons cannot be mixed with CTA or PIX buttons');
3326+
// Reply
3327+
if (hasReplyButtons) {
3328+
if (data.buttons.length > 3) {
3329+
throw new BadRequestException('Maximum of 3 reply buttons allowed');
3330+
}
3331+
if (hasCTAButtons || hasPixButton) {
3332+
throw new BadRequestException('Reply buttons cannot be mixed with CTA or PIX buttons');
3333+
}
33373334
}
3338-
}
33393335

3340-
// PIX
3341-
if (hasPixButton) {
3342-
if (data.buttons.length > 1) {
3343-
throw new BadRequestException('Only one PIX button is allowed');
3336+
// PIX
3337+
if (hasPixButton) {
3338+
if (data.buttons.length > 1) {
3339+
throw new BadRequestException('Only one PIX button is allowed');
3340+
}
3341+
if (hasReplyButtons || hasCTAButtons) {
3342+
throw new BadRequestException('PIX button cannot be mixed with other button types');
3343+
}
3344+
3345+
const message: proto.IMessage = {
3346+
viewOnceMessage: {
3347+
message: {
3348+
interactiveMessage: {
3349+
nativeFlowMessage: {
3350+
buttons: [
3351+
{
3352+
name: this.mapType.get('pix'),
3353+
buttonParamsJson: this.toJSONString(data.buttons[0]),
3354+
},
3355+
],
3356+
messageParamsJson: JSON.stringify({
3357+
from: 'api',
3358+
templateId: v4(),
3359+
}),
3360+
},
3361+
},
3362+
},
3363+
},
3364+
};
3365+
3366+
return await this.sendMessageWithTyping(data.number, message, {
3367+
delay: data?.delay,
3368+
presence: 'composing',
3369+
quoted: data?.quoted,
3370+
mentionsEveryOne: data?.mentionsEveryOne,
3371+
mentioned: data?.mentioned,
3372+
});
33443373
}
3345-
if (hasReplyButtons || hasCTAButtons) {
3346-
throw new BadRequestException('PIX button cannot be mixed with other button types');
3374+
3375+
// CTA (url / call / copy)
3376+
if (hasCTAButtons) {
3377+
if (data.buttons.length > 2) {
3378+
throw new BadRequestException('Maximum of 2 CTA buttons allowed');
3379+
}
3380+
if (hasReplyButtons) {
3381+
throw new BadRequestException('CTA buttons cannot be mixed with reply buttons');
3382+
}
33473383
}
33483384

3385+
/* =========================
3386+
* HEADER (opcional)
3387+
* ========================= */
3388+
3389+
const generatedMedia = data?.thumbnailUrl
3390+
? await this.prepareMediaMessage({ mediatype: 'image', media: data.thumbnailUrl })
3391+
: null;
3392+
3393+
/* =========================
3394+
* BOTÕES
3395+
* ========================= */
3396+
3397+
const buttons = data.buttons.map((btn) => ({
3398+
name: this.mapType.get(btn.type),
3399+
buttonParamsJson: this.toJSONString(btn),
3400+
}));
3401+
3402+
/* =========================
3403+
* MENSAGEM FINAL
3404+
* ========================= */
3405+
33493406
const message: proto.IMessage = {
33503407
viewOnceMessage: {
33513408
message: {
33523409
interactiveMessage: {
3410+
body: {
3411+
text: (() => {
3412+
let text = `*${data.title}*`;
3413+
if (data?.description) {
3414+
text += `\n\n${data.description}`;
3415+
}
3416+
return text;
3417+
})(),
3418+
},
3419+
footer: data?.footer ? { text: data.footer } : undefined,
3420+
header: generatedMedia?.message?.imageMessage
3421+
? {
3422+
hasMediaAttachment: true,
3423+
imageMessage: generatedMedia.message.imageMessage,
3424+
}
3425+
: undefined,
33533426
nativeFlowMessage: {
3354-
buttons: [
3355-
{
3356-
name: this.mapType.get('pix'),
3357-
buttonParamsJson: this.toJSONString(data.buttons[0]),
3358-
},
3359-
],
3427+
buttons,
33603428
messageParamsJson: JSON.stringify({
33613429
from: 'api',
33623430
templateId: v4(),
@@ -3376,78 +3444,6 @@ public async buttonMessage(data: SendButtonsDto) {
33763444
});
33773445
}
33783446

3379-
// CTA (url / call / copy)
3380-
if (hasCTAButtons) {
3381-
if (data.buttons.length > 2) {
3382-
throw new BadRequestException('Maximum of 2 CTA buttons allowed');
3383-
}
3384-
if (hasReplyButtons) {
3385-
throw new BadRequestException('CTA buttons cannot be mixed with reply buttons');
3386-
}
3387-
}
3388-
3389-
/* =========================
3390-
* HEADER (opcional)
3391-
* ========================= */
3392-
3393-
const generatedMedia = data?.thumbnailUrl
3394-
? await this.prepareMediaMessage({ mediatype: 'image', media: data.thumbnailUrl })
3395-
: null;
3396-
3397-
/* =========================
3398-
* BOTÕES
3399-
* ========================= */
3400-
3401-
const buttons = data.buttons.map((btn) => ({
3402-
name: this.mapType.get(btn.type),
3403-
buttonParamsJson: this.toJSONString(btn),
3404-
}));
3405-
3406-
/* =========================
3407-
* MENSAGEM FINAL
3408-
* ========================= */
3409-
3410-
const message: proto.IMessage = {
3411-
viewOnceMessage: {
3412-
message: {
3413-
interactiveMessage: {
3414-
body: {
3415-
text: (() => {
3416-
let text = `*${data.title}*`;
3417-
if (data?.description) {
3418-
text += `\n\n${data.description}`;
3419-
}
3420-
return text;
3421-
})(),
3422-
},
3423-
footer: data?.footer ? { text: data.footer } : undefined,
3424-
header: generatedMedia?.message?.imageMessage
3425-
? {
3426-
hasMediaAttachment: true,
3427-
imageMessage: generatedMedia.message.imageMessage,
3428-
}
3429-
: undefined,
3430-
nativeFlowMessage: {
3431-
buttons,
3432-
messageParamsJson: JSON.stringify({
3433-
from: 'api',
3434-
templateId: v4(),
3435-
}),
3436-
},
3437-
},
3438-
},
3439-
},
3440-
};
3441-
3442-
return await this.sendMessageWithTyping(data.number, message, {
3443-
delay: data?.delay,
3444-
presence: 'composing',
3445-
quoted: data?.quoted,
3446-
mentionsEveryOne: data?.mentionsEveryOne,
3447-
mentioned: data?.mentioned,
3448-
});
3449-
}
3450-
34513447
public async locationMessage(data: SendLocationDto) {
34523448
return await this.sendMessageWithTyping(
34533449
data.number,

0 commit comments

Comments
 (0)