"Quote of the day" help needed. Parse text to convert ascii coddes to text

I've been introduced to a site that gives proverbs.
http request with https://favqs.com/api/qotd in it.

I'm messing around with the google TTS node and am sending the messages from the quote of the day node's output to the TTS.

But - now and then - there are things in like #39 (ok not 100% sure that is it) but the TTS node doesn't parse it for what it is supposed to be,

EDIT

Got one:

Dale Carnegie says If you want to conquer fear, don't sit home and think about it. Go out and get busy.

Through what node do I send the message to convert the ascii code to it's character?

Use the node-red-html-to-text node

I turned to the dark side and asked chatgpt.

It gave me this code:
(Modified parts for my needs)

// Assuming 'msg.payload' contains the received message
var message = msg.payload.quote.body;

// Replace ''' with '
message = message.replace(/'/g, "'");

// Update the payload with the modified message
msg.payload.quote.body = message;

// Return the modified message
return msg;

And it works.

This frightens me.
I asked a computer a question and actually got usable code back.

Yeah, ok, it was initially msg.payload and I had to change it to msg.payload.quote.body but.....
Thanks though.

WELL THERE YA GO!

I tried it and it doesn't work.

Still get/see the ascii code.

I'll try the node you mentioned.

Why use a function node when there is an existing node that will do it for you? Here is a sample flow showing it work:

[{"id":"b8111f78dd481d81","type":"tab","label":"Flow 4","disabled":false,"info":"","env":[]},{"id":"750d6274e6ebcc1d","type":"html-to-text","z":"b8111f78dd481d81","name":"","x":510,"y":160,"wires":[["021745ecc21d8dc1"]]},{"id":"021745ecc21d8dc1","type":"debug","z":"b8111f78dd481d81","name":"debug 3425","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":160,"wires":[]},{"id":"a86842abf99c2444","type":"inject","z":"b8111f78dd481d81","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Dale Carnegie says If you want to conquer fear, don't sit home and think about it. Go out and get busy.","payloadType":"str","x":270,"y":160,"wires":[["750d6274e6ebcc1d"]]}]
1 Like

Because I didn't know the name of the node.

I'm not smart in that way.

I believe it is a core node so just put html in the `filter nodes search (top left on the editor) and it should pop up.

It isn't.

Had to import it.

5 years old... But age isn't a problem. :wink:

Um, sorry, that node ....

Well it doesn't like complicated msg.payloads.

I'll work on it.

Can you show us a payload that it can't handle?

The one I posted is an example.

Dale Carnegie says If you want to conquer fear, don't sit home and think about it. Go out and get busy.

The TTS doesn't like it.

And I am not getting consistent results with the node chatGPT gave me.

I'll have to send that message into it and see what happens.

Ok, here's some more stuff to show you what's happening.

Forgive the other stuff around the nodes. I am testing things.

I SUSPECT the code given to me only needs a slight tweak to get it working.

But that tweak is not in my skill set yet.
This line has my attention though:

message = message.replace(/'/g, "'");

Is that correct?

It works for me.
image

[{"id":"e1fb141be0fe90e2","type":"template","z":"74bffde0d46854ef","name":"Input, wrapped in <p> </p> tags","field":"payload","fieldType":"msg","format":"html","syntax":"mustache","template":"<p>Dale Carnegie says If you want to conquer fear, don&#39;t sit home and think about it. Go out and get busy.</p>","output":"str","x":310,"y":80,"wires":[["8fb94f9ed7a7fd61"]]},{"id":"614c654933da528d","type":"inject","z":"74bffde0d46854ef","name":"Go","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":80,"wires":[["e1fb141be0fe90e2"]]},{"id":"b786d282a0ccbd8e","type":"debug","z":"74bffde0d46854ef","name":"Text","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":80,"wires":[]},{"id":"8fb94f9ed7a7fd61","type":"html","z":"74bffde0d46854ef","name":"html p tag","property":"payload","outproperty":"payload","tag":"p","ret":"text","as":"single","chr":"_","x":520,"y":80,"wires":[["b786d282a0ccbd8e"]]}]

Ok, but now something else is going on.

The structure is now not ...... plain text.

I am getting [ and ] around it.

And so it isn't being seen by the TTS node.

So I've swapped one problem for another.

I'll read the docs on the node and see if I can work out what is happening.

Because it's an array?

Well, ok.

The payload I'm sending into it is a JSON package from https://favqs.com/api/qotd
What chatGPT gave me was for .... msg.payload.

So I changed it/the code from msg.payload to msg.payload.quote.body in the two lines.

// Assuming 'msg.payload' contains the received message
var message = msg.payload.quote.body;

// Replace '&#39;' with '
message = message.replace(/&#39;/g, "'");

// Update the payload with the modified message
msg.payload.quote.body = message;

// Return the modified message
return msg;

So..... all things being equal, it should parse that part of the message and put it back where the original one is/was.
(That is assuming that actually happens - just realised if it isn't, then I've got a whole other problem.)

But it looks like it should work/do it.

Am I wrong with what I did/what I think should/does/is happening?

this will handle only an 'apostrophe' what if there are some other special characters ?

This is TEST code shown here.

No, I can't spell.
I saw that after I took the picture.

That is a TEST and I save the message into boo as well.

I saw it got changed but it was doby not body. I'll cop that.

The message not pointed to goes through the other node, but it's spelling IS correct.

So this is the lower part expanded.

Same message arriving.
CORRECT part of message addressed/accessed/(what ever)
You can see that the one on the previous pictures DID change the message - although I didn't spell body correctly and also have boo for checking.
So the code - which is the same (mostly) to this one worked.
This one doesn't.

Where's the elephant I am not seeing?

FOUND IT!

STUPID ME!

The template nodes!

I had {{ }} when I needed {{{ }}}

Changed to triple and it works!

Greatest apologies to all who offered help for that silly mistake.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.