Skip to content

Commit e4b6f4f

Browse files
committed
correction in message formatting when generated by AI as markdown in typebot
1 parent f0d40ee commit e4b6f4f

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* 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)
66
* New global mode for rabbitmq events
77

8+
### Fixed
9+
* Correction in message formatting when generated by AI as markdown in typebot
10+
811
# 1.7.5 (2024-05-21 08:50)
912

1013
### Fixed

src/api/integrations/typebot/services/typebot.service.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -519,18 +519,32 @@ export class TypebotService {
519519
text += element.text;
520520
}
521521

522-
if (
523-
element.children &&
524-
(element.type === 'p' ||
525-
element.type === 'a' ||
526-
element.type === 'inline-variable' ||
527-
element.type === 'variable')
528-
) {
522+
if (element.children && element.type !== 'a') {
529523
for (const child of element.children) {
530524
text += applyFormatting(child);
531525
}
532526
}
533527

528+
if (element.type === 'p') {
529+
text = text.trim() + '\n';
530+
}
531+
532+
if (element.type === 'ol') {
533+
text =
534+
'\n' +
535+
text
536+
.split('\n')
537+
.map((line, index) => (line ? `${index + 1}. ${line}` : ''))
538+
.join('\n');
539+
}
540+
541+
if (element.type === 'li') {
542+
text = text
543+
.split('\n')
544+
.map((line) => (line ? ` ${line}` : ''))
545+
.join('\n');
546+
}
547+
534548
let formats = '';
535549

536550
if (element.bold) {
@@ -558,6 +572,7 @@ export class TypebotService {
558572
for (const message of messages) {
559573
if (message.type === 'text') {
560574
let formattedText = '';
575+
console.log('message.content', message.content);
561576

562577
for (const richText of message.content.richText) {
563578
for (const element of richText.children) {

0 commit comments

Comments
 (0)