mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Twitter node: Add support for search terms passed in through msg.payload (#235)
* Add support for search terms passed in through msg.payload * Add support for dynamic left ping connector * Suggestions from David Conway-Jones * Better error message * Add green status indicator when msg.payload is dynamically passed in and revised warning messages
This commit is contained in:
parent
8e84e19cde
commit
b0c93e44b8
@ -124,7 +124,7 @@
|
||||
<li>all tweets by specific users</li>
|
||||
<li>direct messages received by the authenticated user</li>
|
||||
</ul></p>
|
||||
<p>Use space for <i>and</i> and comma , for <i>or</i> when searching for multiple terms.</p>
|
||||
<p>Use space for <i>and</i> and comma , for <i>or</i> when searching for multiple terms. If you want to pass in the term(s) via the <code>msg.payload</code>, leave the field blank.</p>
|
||||
<p>Sets the <code>msg.topic</code> to <i>tweets/</i> and then appends the senders screen name.</p>
|
||||
<p>Sets <code>msg.location</code> to the tweeters location if known.</p>
|
||||
<p>Sets <code>msg.tweet</code> to the full tweet object as documented by <a href="https://dev.twitter.com/overview/api/tweets">Twitter</a>.
|
||||
@ -140,7 +140,7 @@
|
||||
color:"#C0DEED",
|
||||
defaults: {
|
||||
twitter: {type:"twitter-credentials",required:true},
|
||||
tags: {value:"",validate:function(v) { return this.user == "dm" || v.length > 0;}},
|
||||
tags: {value:""},
|
||||
user: {value:"false",required:true},
|
||||
name: {value:""},
|
||||
topic: {value:"tweets"}
|
||||
@ -184,6 +184,16 @@
|
||||
|
||||
});
|
||||
$("#node-input-user").change();
|
||||
},
|
||||
oneditsave: function() {
|
||||
if ($('#node-input-tags').val() == '' && $("#node-input-user option:selected").val() != 'dm'
|
||||
&& $("#node-input-user option:selected").val() != 'user') {
|
||||
this.inputs=1;
|
||||
}
|
||||
else {
|
||||
//set back the default state of 0 inputs
|
||||
this.inputs=0;
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
@ -89,6 +89,7 @@ module.exports = function(RED) {
|
||||
node.poll_ids = [];
|
||||
node.since_ids = {};
|
||||
var users = node.tags.split(",");
|
||||
if (users == '') node.warn("User option selected but no users specified");
|
||||
for (var i=0;i<users.length;i++) {
|
||||
var user = users[i].replace(" ","");
|
||||
twit.getUserTimeline({
|
||||
@ -182,7 +183,7 @@ module.exports = function(RED) {
|
||||
},120000));
|
||||
});
|
||||
|
||||
} else if (this.tags !== "") {
|
||||
} else {
|
||||
try {
|
||||
var thing = 'statuses/filter';
|
||||
if (this.user === "true") { thing = 'user'; }
|
||||
@ -235,14 +236,29 @@ module.exports = function(RED) {
|
||||
});
|
||||
}
|
||||
}
|
||||
setupStream();
|
||||
if (this.tags == '')
|
||||
{
|
||||
this.warn("No search term(s) specified - add to node config or pass in through msg.payload");
|
||||
}
|
||||
else setupStream();
|
||||
node.on("input", function(msg) {
|
||||
if (this.tags == '') {
|
||||
this.warn("Now searching for: " + msg.payload);
|
||||
if (this.stream) this.stream.destroy();
|
||||
st = { track: [msg.payload] };
|
||||
setupStream();
|
||||
node.status({fill:"green",shape:"dot",text:msg.payload});
|
||||
}
|
||||
//We shouldn't get into this state, but just incase, check for it
|
||||
else {
|
||||
this.warn("msg.payload passed in, but tag config is not blank, defaulting to tag config");
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
node.error(err);
|
||||
}
|
||||
} else {
|
||||
this.error(RED._("twitter.errors.invalidtag"));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.error(RED._("twitter.errors.missingcredentials"));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user