mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-24 09:28:39 -06:00
fix: correction in typebot text formatting
This commit is contained in:
parent
2aadd1cac5
commit
6983f385fc
@ -389,6 +389,7 @@ export class TypebotService {
|
|||||||
input,
|
input,
|
||||||
clientSideActions,
|
clientSideActions,
|
||||||
this.eventEmitter,
|
this.eventEmitter,
|
||||||
|
applyFormatting,
|
||||||
).catch((err) => {
|
).catch((err) => {
|
||||||
console.error('Erro ao processar mensagens:', err);
|
console.error('Erro ao processar mensagens:', err);
|
||||||
});
|
});
|
||||||
@ -404,72 +405,64 @@ export class TypebotService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processMessages(instance, messages, input, clientSideActions, eventEmitter) {
|
function applyFormatting(element) {
|
||||||
|
let text = '';
|
||||||
|
|
||||||
|
if (element.text) {
|
||||||
|
text += element.text;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (element.type === 'p' || element.type === 'inline-variable') {
|
||||||
|
for (const child of element.children) {
|
||||||
|
text += applyFormatting(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let formats = '';
|
||||||
|
|
||||||
|
if (element.bold) {
|
||||||
|
formats += '*';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (element.italic) {
|
||||||
|
formats += '_';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (element.underline) {
|
||||||
|
formats += '~';
|
||||||
|
}
|
||||||
|
|
||||||
|
let formattedText = `${formats}${text}${formats.split('').reverse().join('')}`;
|
||||||
|
|
||||||
|
if (element.url) {
|
||||||
|
const linkText = element.children[0]?.text || '';
|
||||||
|
formattedText = `[${linkText}](${element.url})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return formattedText;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function processMessages(instance, messages, input, clientSideActions, eventEmitter, applyFormatting) {
|
||||||
for (const message of messages) {
|
for (const message of messages) {
|
||||||
const wait = findItemAndGetSecondsToWait(clientSideActions, message.id);
|
const wait = findItemAndGetSecondsToWait(clientSideActions, message.id);
|
||||||
|
|
||||||
if (message.type === 'text') {
|
if (message.type === 'text') {
|
||||||
let formattedText = '';
|
let formattedText = '';
|
||||||
|
|
||||||
let linkPreview = false;
|
|
||||||
|
|
||||||
for (const richText of message.content.richText) {
|
for (const richText of message.content.richText) {
|
||||||
if (richText.type === 'variable') {
|
for (const element of richText.children) {
|
||||||
for (const child of richText.children) {
|
formattedText += applyFormatting(element);
|
||||||
for (const grandChild of child.children) {
|
|
||||||
formattedText += grandChild.text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (const element of richText.children) {
|
|
||||||
let text = '';
|
|
||||||
|
|
||||||
if (element.type === 'inline-variable') {
|
|
||||||
for (const child of element.children) {
|
|
||||||
for (const grandChild of child.children) {
|
|
||||||
text += grandChild.text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (element.text) {
|
|
||||||
text = element.text;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (element.text) {
|
|
||||||
// text = element.text;
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (element.bold) {
|
|
||||||
text = `*${text}*`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (element.italic) {
|
|
||||||
text = `_${text}_`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (element.underline) {
|
|
||||||
text = `*${text}*`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (element.url) {
|
|
||||||
const linkText = element.children[0].text;
|
|
||||||
text = `[${linkText}](${element.url})`;
|
|
||||||
linkPreview = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
formattedText += text;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
formattedText += '\n';
|
formattedText += '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
formattedText = formattedText.replace(/\n$/, '');
|
formattedText = formattedText.replace(/\*\*/g, '').replace(/__/, '').replace(/~~/, '').replace(/\n$/, '');
|
||||||
|
|
||||||
await instance.textMessage({
|
await instance.textMessage({
|
||||||
number: remoteJid.split('@')[0],
|
number: remoteJid.split('@')[0],
|
||||||
options: {
|
options: {
|
||||||
delay: wait ? wait * 1000 : instance.localTypebot.delay_message || 1000,
|
delay: wait ? wait * 1000 : instance.localTypebot.delay_message || 1000,
|
||||||
presence: 'composing',
|
presence: 'composing',
|
||||||
linkPreview: linkPreview,
|
|
||||||
},
|
},
|
||||||
textMessage: {
|
textMessage: {
|
||||||
text: formattedText,
|
text: formattedText,
|
||||||
@ -537,7 +530,6 @@ export class TypebotService {
|
|||||||
options: {
|
options: {
|
||||||
delay: 1200,
|
delay: 1200,
|
||||||
presence: 'composing',
|
presence: 'composing',
|
||||||
linkPreview: false,
|
|
||||||
},
|
},
|
||||||
textMessage: {
|
textMessage: {
|
||||||
text: formattedText,
|
text: formattedText,
|
||||||
|
Loading…
Reference in New Issue
Block a user