Share feedback, ideas and get community help

Updated 12 months ago

Parse response api to whatsapp

Does someone has some code to parse the response coming from typebot api to send it to other whatsapp number? After I make http posts frommybackend to typebot ai, I have seen nany text, url.... and childrens nested come from typebot api. It becomes hard capture all possibilities.
B
L
20 comments
What you receive is a richText list
It can be transformed either manually (by parsing the nested text nodes recursively). Or using the Node.js remark-slate library.
Here is how it's transformed on Typebot for WhatsApp currently:

Plain Text
import { TElement } from '@udecode/plate-common'
import { serialize } from 'remark-slate'

export const convertRichTextToWhatsAppText = (richText: TElement[]): string =>
  richText
    .map((chunk) =>
      serialize(chunk)?.replaceAll('**', '*').replaceAll(''', "'")
    )
    .join('\n')
Hi @Baptiste I have adpated the code to my case. But it seems this function is not getting a tag as url. Fo sample, I have the next messages array attached. I am using the next code:
export const convertRichTextToWhatsAppText = (richText: TElement[]): string =>
richText
.map(chunk =>
serialize(chunk)?.replaceAll("*", "").replaceAll("'", "'")
)
.join("\n");

export const convertMessageToWhatsAppMessage = (
message: any
): string | undefined => {
switch (message.type) {
case "text": {
if (!message.content.richText

message.content.richText.length === 0)
return undefined;

const txt = convertRichTextToWhatsAppText(message.content.richText);
console.log("txt", txt);
return txt;
}
case "image": {
if (!message.content.url

isImageUrlNotCompatible(message.content.url))
return undefined;
return message.content.url;
}
case "audio": {
if (!message.content.url) return undefined;
return message.content.url;
}
case "video": {
if (
!message.content.url ||
(message.content.type !== "url" &&
isVideoUrlNotCompatible(message.content.url))
)
return undefined;
return message.content.url;
}
case "embed": {
if (!message.content.url) return undefined;
return message.content.url;
}
}
return undefined;
};
In my console.log I see only:
txt---->>>>> Clique aqui para baixar o documento

No url content is showing here
You need to format it as Markdown
Something like: link text
I can't format it because I put a console log in return of your function, but it´s never returned from it when the tag contains a url as type. For sample:
"children": [
{
"text": ""
},
{
"url": "https://Sistema.com.br/web.dll/AAA?Token=1002494XXX",
"type": "a",
"children": [
{
"text": "Clique aqui para baixar o documento"
}
]
},
{
"text": ""
}
]
}
The text is returned but not the url
Sorry I didn't get it, your message is not well formatted 😅
The message containing the staff to be parsed I am capturing from typebot api
I can pass the complete message to you. OK?
I have a node backend code that get the typebot http api response e format it to send to whatsapp. One moment, please and I will put here the complete messages.
I can try it out on my end
Ok I can reproduce
Hi @Baptiste . Sorry, but this question was solved in the latest version?
Add a reply
Sign up and join the conversation on Discord