Extract \n from a string to build an array

I think the issue is that the split wants payload to be a JSON object, rather than a string.

I wrote this little demonstration test rig based on what @dceejay 's findings

    {
        "id": "3df7822c7506fec0",
        "type": "inject",
        "z": "60c7ee1b0aa52cb1",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "A String wrapped in Quotes",
        "payload": "\"test\\ntesting\\ntested\"",
        "payloadType": "str",
        "x": 1740,
        "y": 480,
        "wires": [
            [
                "f483724e0e78e459"
            ]
        ]
    },
    {
        "id": "db39f2a737442ad8",
        "type": "split",
        "z": "60c7ee1b0aa52cb1",
        "name": "",
        "splt": "\\n",
        "spltType": "str",
        "arraySplt": 1,
        "arraySpltType": "len",
        "stream": false,
        "addname": "",
        "x": 1870,
        "y": 580,
        "wires": [
            [
                "4f82397f2dc39891"
            ]
        ]
    },
    {
        "id": "4f82397f2dc39891",
        "type": "debug",
        "z": "60c7ee1b0aa52cb1",
        "name": "debug 12",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 2020,
        "y": 580,
        "wires": []
    },
    {
        "id": "4420f9ea1847302e",
        "type": "json",
        "z": "60c7ee1b0aa52cb1",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": true,
        "x": 1730,
        "y": 580,
        "wires": [
            [
                "db39f2a737442ad8"
            ]
        ]
    },
    {
        "id": "52a40740afcc5fee",
        "type": "split",
        "z": "60c7ee1b0aa52cb1",
        "name": "",
        "splt": "\\n",
        "spltType": "str",
        "arraySplt": 1,
        "arraySpltType": "len",
        "stream": false,
        "addname": "",
        "x": 1730,
        "y": 620,
        "wires": [
            [
                "942da39989059ead"
            ]
        ]
    },
    {
        "id": "942da39989059ead",
        "type": "debug",
        "z": "60c7ee1b0aa52cb1",
        "name": "debug 13",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1880,
        "y": 620,
        "wires": []
    },
    {
        "id": "9c89a946d80f6627",
        "type": "link in",
        "z": "60c7ee1b0aa52cb1",
        "name": "link in 2",
        "links": [
            "f483724e0e78e459"
        ],
        "x": 1625,
        "y": 600,
        "wires": [
            [
                "4420f9ea1847302e",
                "52a40740afcc5fee"
            ]
        ]
    },
    {
        "id": "b7d9d6194b240af0",
        "type": "inject",
        "z": "60c7ee1b0aa52cb1",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "a plain String",
        "payload": "test\\ntesting\\ntested",
        "payloadType": "str",
        "x": 1730,
        "y": 520,
        "wires": [
            [
                "f483724e0e78e459"
            ]
        ]
    },
    {
        "id": "cecc4ac40c754d19",
        "type": "inject",
        "z": "60c7ee1b0aa52cb1",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "\"Payload is a JSON Object of a String\"",
        "payload": "\"test\\ntesting\\ntested\"",
        "payloadType": "json",
        "x": 1740,
        "y": 440,
        "wires": [
            [
                "f483724e0e78e459"
            ]
        ]
    },
    {
        "id": "f483724e0e78e459",
        "type": "link out",
        "z": "60c7ee1b0aa52cb1",
        "name": "link out 4",
        "mode": "link",
        "links": [
            "9c89a946d80f6627"
        ],
        "x": 1925,
        "y": 480,
        "wires": []
    }
]

So it seems like the main issue is that the split node wants the payload to be a JSON object rather than a raw string.

You can see in my new test example how the 3 different types interact with the split node.

JSON is always a string, do you mean that it wants it to be a javascript object?

I do plan on doing more testing to see how robust this ends up being. the \n I'm at least confident will work, if only because the email starts formatted with those line spacings.

The return the HTML only is an interesting idea. I'm fetching the email from Google mailboxes, so I would assume if Google gives me the payload and the HTML as separate elements in the payload from my email node, I should be fine right? Even if the client Mail only sends HTML, presumably the Google mail outputs the payload the same.

Selecting between them is easy, the email node gives the english parsed email as a separate element from HTML. I suppose if push came to shove, I could parse the HTML instead. I don't think tha'ts a huge concern though, because I have other Robot scripts that read emails in a similar manner and they don't have any problem with reading the message subject etc.

One of the other scripts I have allows users in my company to email asana@company.com and based on who sent the message, the subject and text, creates an Asana task for follow up.

If users modify the questions I provide, the return code is -1 (no match) I can then start searching the start of each line for the question, using the length of the question for the search.

If it still turns up nothing, then I have it reduce by a certain percentage of the length and search again (assuming they modified the end of the question)

But by that point, it will be flagged for inspection, since it didn't match exactly, and will need to be looked at before all the answers are recorded.

Yes.

I'm not really a dev, hence why I use block programmers.... I'm pretty loosy goosy when it comes to the terms.. I fell into this field from entertainment control systems needing to interface with weird stuff.

I mean that it wants a Javascript Object containing a string.

By sending that JSON Node a string wrapped in quotes, that's a JSON string that represents a Javascript Object of just a string, which the node converts to a javascript object Thereby making the Split Node happy.

It's been too long since I had to dig into email formatting. A raw email will typically contain both the HTML and the text versions of the email encoded as a multi-part. But not all email clients play nicely (probably not so much of an issue these days) so remember that it isn't just about what Gmail returns, it is also about what the users mail client and mail server did to the source message. But yes, in general, you would expect that even when a users mail client is set to send HTML, there will normally be a text version embedded in one of the parts.

OK, so if the users of this are using a known email client, that makes it easier for sure. And is likely to also be easier if they are used to this style of interaction. It's just that I know users - if they can mess it up, they certainly will. :slight_smile:

In my own varied past, I've several times written systems that relied on email - but in those cases, I used a pre-formatted Excel attachment so the text in the email wasn't important.

BTW, if you are a Microsoft house, they have a quite clever method to have structured forms included in emails. But of course, you need Microsoft infrastructure to work with that.

Yes but that's a different Robot Flow.

This one is used by our clients where the systems are installed, so there will likely be every kind of email client sending the email to our support inbox.

i thought about making it a form that was attached, but in the end I figured if the QR Code opens their email app and starts a draft for them, they are more likely to answer some questions and hit send, rather than filling a form and attaching it.

Plus this way I can still use attachments that get sent with the email without having to parse them. I can download the attachments directly into dropbox so anyone in the company can review the attachments.

Thanks for your input. I'll follow up on how well the system works overall.

If you are using that, why not use it to open a form and just submit the form to a db? Not sure if you are a Microsoft house but if you are, MS Forms might do it. A Dashboard form would also do as long as you are happy to create an internet facing secure connection.

I think for a few reasons, in no particular order

  1. I haven't worked with forms too much. I probably could make a Google form amd have it handle the responses.

  2. I'm using a custom QR manager, where I can update the data stored in the QRCode without changing the QR. So if it was a form, I'd have to update which form it's linked too, then update the data in the form.

  3. Scanning a QR Code that then opens your email app immediately gives me one point of contact, their email address which was filled in by their mail client, even if they send in a form they didn't update.

  4. I may in the future consider an automatic method of updating the email form from a text document from Node RED, which again I could probably do with a Google firm, but I think it would be easier to do from Node Red through the email form.

  5. Psychology. The client has an email they sent and a response from that.

They have their own receipt and can follow up if there is a problem

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