Skip to content

Commit

Permalink
correction in message formatting when generated by AI as markdown in …
Browse files Browse the repository at this point in the history
…typebot
  • Loading branch information
DavidsonGomes committed May 27, 2024
1 parent f0d40ee commit e4b6f4f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* Now in the manager, when logging in with the client's apikey, the listing only shows the instance corresponding to the provided apikey (only with MongoDB)
* New global mode for rabbitmq events

### Fixed
* Correction in message formatting when generated by AI as markdown in typebot

# 1.7.5 (2024-05-21 08:50)

### Fixed
Expand Down
29 changes: 22 additions & 7 deletions src/api/integrations/typebot/services/typebot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,18 +519,32 @@ export class TypebotService {
text += element.text;
}

if (
element.children &&
(element.type === 'p' ||
element.type === 'a' ||
element.type === 'inline-variable' ||
element.type === 'variable')
) {
if (element.children && element.type !== 'a') {
for (const child of element.children) {
text += applyFormatting(child);
}
}

if (element.type === 'p') {
text = text.trim() + '\n';
}

if (element.type === 'ol') {
text =
'\n' +
text
.split('\n')
.map((line, index) => (line ? `${index + 1}. ${line}` : ''))
.join('\n');
}

if (element.type === 'li') {
text = text
.split('\n')
.map((line) => (line ? ` ${line}` : ''))
.join('\n');
}

let formats = '';

if (element.bold) {
Expand Down Expand Up @@ -558,6 +572,7 @@ export class TypebotService {
for (const message of messages) {
if (message.type === 'text') {
let formattedText = '';
console.log('message.content', message.content);

for (const richText of message.content.richText) {
for (const element of richText.children) {
Expand Down

3 comments on commit e4b6f4f

@antonioaraujo664
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

salvou legal, obrigado. Ja ta no repo do docker? \o/

@VitorAf0nso
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do i install this?

Como eu instalo isso? Não sei concertar.

@VitorAf0nso
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

salvou legal, obrigado. Ja ta no repo do docker? \o/

sabe me ajudar a arrumar o meu? não sei como faz funcionar isso

Please sign in to comment.