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

**URL:** <https://discourse.nodered.org/t/quote-of-the-day-help-needed-parse-text-to-convert-ascii-coddes-to-text/89399>\
**Category:** General\
**Created:** [10 July 2024 10:27 UTC](https://discourse.nodered.org/t/quote-of-the-day-help-needed-parse-text-to-convert-ascii-coddes-to-text/89399 "2024-07-10T10:27:10Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 July 2024 10:27 UTC](https://discourse.nodered.org/t/quote-of-the-day-help-needed-parse-text-to-convert-ascii-coddes-to-text/89399/1 "2024-07-10T10:27:10Z")

</div>

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:

```auto
Dale Carnegie says If you want to conquer fear, don&#39;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?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [10 July 2024 11:28 UTC](https://discourse.nodered.org/t/quote-of-the-day-help-needed-parse-text-to-convert-ascii-coddes-to-text/89399/2 "2024-07-10T11:28:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 July 2024 11:31 UTC](https://discourse.nodered.org/t/quote-of-the-day-help-needed-parse-text-to-convert-ascii-coddes-to-text/89399/3 "2024-07-10T11:31:18Z")

</div>

I _turned to the dark side_ and asked `chatgpt`.

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

```auto
// 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;

```

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.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [10 July 2024 11:32 UTC](https://discourse.nodered.org/t/quote-of-the-day-help-needed-parse-text-to-convert-ascii-coddes-to-text/89399/4 "2024-07-10T11:32:36Z")

</div>

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:

```auto
[{"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&#39;t sit home and think about it. Go out and get busy.","payloadType":"str","x":270,"y":160,"wires":[["750d6274e6ebcc1d"]]}]

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 July 2024 11:33 UTC](https://discourse.nodered.org/t/quote-of-the-day-help-needed-parse-text-to-convert-ascii-coddes-to-text/89399/5 "2024-07-10T11:33:49Z")

</div>

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

I'm not smart in that way.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [10 July 2024 11:37 UTC](https://discourse.nodered.org/t/quote-of-the-day-help-needed-parse-text-to-convert-ascii-coddes-to-text/89399/6 "2024-07-10T11:37:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 July 2024 11:37 UTC](https://discourse.nodered.org/t/quote-of-the-day-help-needed-parse-text-to-convert-ascii-coddes-to-text/89399/7 "2024-07-10T11:37:51Z")

</div>

It isn't.

Had to import it.

`5` years old... But age isn't a problem. 😉

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 July 2024 11:39 UTC](https://discourse.nodered.org/t/quote-of-the-day-help-needed-parse-text-to-convert-ascii-coddes-to-text/89399/8 "2024-07-10T11:39:24Z")

</div>

Um, sorry, that node ....

Well it doesn't like complicated `msg.payloads`.

I'll work on it.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [10 July 2024 11:46 UTC](https://discourse.nodered.org/t/quote-of-the-day-help-needed-parse-text-to-convert-ascii-coddes-to-text/89399/9 "2024-07-10T11:46:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 July 2024 11:48 UTC](https://discourse.nodered.org/t/quote-of-the-day-help-needed-parse-text-to-convert-ascii-coddes-to-text/89399/10 "2024-07-10T11:48:54Z")

</div>

The one I posted is an example.

` Dale Carnegie says If you want to conquer fear, don&#39;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.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 July 2024 11:54 UTC](https://discourse.nodered.org/t/quote-of-the-day-help-needed-parse-text-to-convert-ascii-coddes-to-text/89399/11 "2024-07-10T11:54:47Z")

</div>

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

 ![Screenshot from 2024-07-10 21-51-12](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/a/caac3060d80c90b7dfd40973aab0d3dd3c9b9e3f.png)

 ![Screenshot from 2024-07-10 21-52-54](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/7/472604a91a0b3d925f974f0d611e7f4fbac6bdd5.png)

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(/&#39;/g, "'");`

Is that correct?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [10 July 2024 11:58 UTC](https://discourse.nodered.org/t/quote-of-the-day-help-needed-parse-text-to-convert-ascii-coddes-to-text/89399/12 "2024-07-10T11:58:04Z")

</div>

> [@Trying\_to\_learn](#):
>
> The one I posted is an example.

It works for me.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/7/579804dfdde8b177f95d466d9eb108f5a6fd95dc.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/4/146f58b534a563369dd27ba5175687d80bab0e0f.png)

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 July 2024 12:03 UTC](https://discourse.nodered.org/t/quote-of-the-day-help-needed-parse-text-to-convert-ascii-coddes-to-text/89399/13 "2024-07-10T12:03:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [10 July 2024 12:03 UTC](https://discourse.nodered.org/t/quote-of-the-day-help-needed-parse-text-to-convert-ascii-coddes-to-text/89399/14 "2024-07-10T12:03:55Z")

</div>

Because it's an array?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 July 2024 12:08 UTC](https://discourse.nodered.org/t/quote-of-the-day-help-needed-parse-text-to-convert-ascii-coddes-to-text/89399/15 "2024-07-10T12:08:33Z")

</div>

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.

```auto
// 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?

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [10 July 2024 12:19 UTC](https://discourse.nodered.org/t/quote-of-the-day-help-needed-parse-text-to-convert-ascii-coddes-to-text/89399/16 "2024-07-10T12:19:41Z")

</div>

> [@Trying\_to\_learn](#):
>
> `'&#39;'`

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

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 July 2024 12:26 UTC](https://discourse.nodered.org/t/quote-of-the-day-help-needed-parse-text-to-convert-ascii-coddes-to-text/89399/17 "2024-07-10T12:26:58Z")

</div>

![Screenshot from 2024-07-10 22-18-22](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/4/e446a36604b6f75789fb75a5f7a3b73ae7b31bc9.png)

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.

 ![Screenshot from 2024-07-10 22-23-22](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/f/3f19f6b605def5b4f41bf6229210042a8e6b3f9b.png)

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?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 July 2024 12:32 UTC](https://discourse.nodered.org/t/quote-of-the-day-help-needed-parse-text-to-convert-ascii-coddes-to-text/89399/18 "2024-07-10T12:32:24Z")

</div>

# 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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [24 July 2024 12:33 UTC](https://discourse.nodered.org/t/quote-of-the-day-help-needed-parse-text-to-convert-ascii-coddes-to-text/89399/19 "2024-07-24T12:33:06Z")

</div>

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