Search code examples
javascriptjsonfilternode-red

How to filter information from an output that consists of "X": "Y",


I'm working with NodeRed and using a Twitter node. I'm trying to figure out how to reply to users if they tweet 'X'.

The output consists of a load of information all comma separated and all consist of "x": "y",

As in "User": "SanderSchaeffer", "Tweet": "This is my tweet", "date": "01-02-2015", etc.

How would I filter, preferably with Javascript or JSON, just the information that is contained by "user"? So the output would be 'SanderSchaeffer'?

Or bottom-line: How do I reply to a user with NodeRed? :)

Apologies for the inconvenient title, but I don't know the name of this way of information output


Solution

  • You can use the Node-RED Switch node to filter.

    You can set it to act on the msg.payload value and use the contains option and then enter the text you want to match on into the box.

    This should only allow Tweets which match through. You then probably want to use a function node to craft a suitable response.

    EDIT:

    To get just the sending user id then you would access it from within the function node as follows:

    msg.tweet.user.screen_name