2013-09-05 16:02:48 +02:00
<!--
Copyright 2013 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
< script type = "text/x-red" data-template-name = "twitter-credentials" >
< div class = "form-row" id = "node-config-twitter-row" > < / div >
< input type = "hidden" id = "node-config-input-screen_name" >
< / script >
< script type = "text/javascript" >
2014-07-20 23:00:02 +02:00
(function() {
2013-09-05 16:02:48 +02:00
var twitterConfigNodeId = null;
var twitterConfigNodeIntervalId = null;
function showTwitterAuthStart() {
var pathname = document.location.pathname;
if (pathname.slice(-1) != "/") {
pathname += "/";
}
2014-07-20 23:00:02 +02:00
var callback = encodeURIComponent(location.protocol+"//"+location.hostname+":"+location.port+pathname+"twitter-credentials/"+twitterConfigNodeId+"/auth/callback");
2014-09-08 15:41:39 +02:00
$("#node-config-dialog-ok").button("disable");
$("#node-config-twitter-row").html('< div style = "text-align: center; margin-top: 20px; " > < a class = "btn" id = "node-config-twitter-start" href = "twitter-credentials/'+twitterConfigNodeId+'/auth?callback='+callback+'" target = "_blank" > Click here to authenticate with Twitter.< / a > < / div > ');
2013-09-05 16:02:48 +02:00
$("#node-config-twitter-start").click(function() {
twitterConfigNodeIntervalId = window.setTimeout(pollTwitterCredentials,2000);
});
}
function updateTwitterScreenName(sn) {
$("#node-config-input-screen_name").val(sn);
2014-09-03 16:11:10 +02:00
$("#node-config-twitter-row").html('< label > < i class = "fa fa-user" > < / i > Twitter ID< / label > < span class = "input-xlarge uneditable-input" > '+sn+'< / span > ');
2013-09-05 16:02:48 +02:00
}
function pollTwitterCredentials(e) {
2014-07-20 23:00:02 +02:00
$.getJSON('credentials/twitter-credentials/'+twitterConfigNodeId,function(data) {
if (data.screen_name) {
updateTwitterScreenName(data.screen_name);
2013-09-05 16:02:48 +02:00
twitterConfigNodeIntervalId = null;
2014-09-08 15:41:39 +02:00
$("#node-config-dialog-ok").button("enable");
2013-09-05 16:02:48 +02:00
} else {
twitterConfigNodeIntervalId = window.setTimeout(pollTwitterCredentials,2000);
}
})
}
RED.nodes.registerType('twitter-credentials',{
category: 'config',
defaults: {
2014-07-20 23:00:02 +02:00
screen_name: {value:""}
2013-09-05 16:02:48 +02:00
},
2014-07-20 23:00:02 +02:00
credentials: {
screen_name: {type:"text"},
access_token: {type: "password"},
access_token_secret: {type:"password"}
},
2013-09-05 16:02:48 +02:00
label: function() {
return this.screen_name;
},
exportable: false,
oneditprepare: function() {
twitterConfigNodeId = this.id;
if (!this.screen_name || this.screen_name == "") {
showTwitterAuthStart();
} else {
2014-07-20 23:00:02 +02:00
if (this.credentials.screen_name) {
updateTwitterScreenName(this.credentials.screen_name);
} else {
showTwitterAuthStart();
}
2013-09-05 16:02:48 +02:00
}
},
oneditsave: function() {
if (twitterConfigNodeIntervalId) {
window.clearTimeout(twitterConfigNodeIntervalId);
}
},
oneditcancel: function(adding) {
if (twitterConfigNodeIntervalId) {
window.clearTimeout(twitterConfigNodeIntervalId);
}
}
});
2014-07-20 23:00:02 +02:00
})();
2013-09-05 16:02:48 +02:00
< / script >
< script type = "text/x-red" data-template-name = "twitter in" >
2013-11-15 09:59:06 +01:00
< div class = "form-row" >
2014-09-03 16:11:10 +02:00
< label for = "node-input-twitter" > < i class = "fa fa-user" > < / i > Log in as< / label >
2013-10-06 00:09:55 +02:00
< input type = "text" id = "node-input-twitter" >
< / div >
2013-11-15 09:59:06 +01:00
< div class = "form-row" >
2014-09-03 16:11:10 +02:00
< label for = "node-input-user" > < i class = "fa fa-search" > < / i > Search< / label >
2013-11-15 09:59:06 +01:00
< select type = "text" id = "node-input-user" style = "display: inline-block; vertical-align: middle; width:60%;" >
< option value = "false" > all public tweets< / option >
< option value = "true" > the tweets of who you follow< / option >
2013-11-23 00:07:08 +01:00
< option value = "user" > the tweets of specific users< / option >
2013-11-23 22:48:17 +01:00
< option value = "dm" > your direct messages< / option >
2013-11-15 09:59:06 +01:00
< / select >
< / div >
2013-11-23 22:48:17 +01:00
< div class = "form-row" id = "node-input-tags-row" >
2014-09-03 16:11:10 +02:00
< label for = "node-input-tags" > < i class = "fa fa-tags" > < / i > < span id = "node-input-tags-label" > for< / span > < / label >
2013-10-02 22:14:02 +02:00
< input type = "text" id = "node-input-tags" placeholder = "comma-separated words, @ids, #tags" >
2013-09-05 16:02:48 +02:00
< / div >
< div class = "form-row" >
2014-09-03 16:11:10 +02:00
< label for = "node-input-name" > < i class = "fa fa-tag" > < / i > Name< / label >
2013-09-05 16:02:48 +02:00
< input type = "text" id = "node-input-name" placeholder = "Name" >
< / div >
2013-10-03 00:37:26 +02:00
< div class = "form-tips" > Tip: Use commas without spaces between multiple search terms. Comma = OR, Space = AND.
2013-10-06 00:09:55 +02:00
< br / > The Twitter API WILL NOT deliver 100% of all tweets.
< br / > Tweets of who you follow will include their retweets and favourites.< / div >
2013-09-05 16:02:48 +02:00
< / script >
< script type = "text/x-red" data-help-name = "twitter in" >
2013-11-24 17:48:24 +01:00
< p > Twitter input node. Can be used to search either:
< ul > < li > the public or a user's stream for tweets containing the configured search term< / li >
< li > all tweets by specific users< / li >
< li > direct messages received by the authenticated user< / li >
< / ul > < / p >
2013-11-15 09:59:06 +01:00
< p > Use space for < i > and< / i > and comma , for < i > or< / i > when searching for multiple terms.< / p >
< p > Sets the < b > msg.topic< / b > to < i > tweets/< / i > and then appends the senders screen name.< / p >
< p > Sets < b > msg.location< / b > to the tweeters location if known.< / p >
< p > Sets < b > msg.tweet< / b > to the full tweet object as documented by < a href = "https://dev.twitter.com/docs/platform-objects/tweets" > Twitter< / a > .
2013-11-25 22:46:15 +01:00
< p > < b > Note:< / b > when set to a specific user's tweets, or your direct messages, the node is subject to
Twitter's API rate limiting. If you deploy the flows multiple times within a 15 minute window, you may
exceed the limit and will see errors from the node. These errors will clear when the current 15 minute window
passes.< / p >
2013-09-05 16:02:48 +02:00
< / script >
< script type = "text/javascript" >
RED.nodes.registerType('twitter in',{
category: 'social-input',
color:"#C0DEED",
defaults: {
twitter: {type:"twitter-credentials",required:true},
2013-11-25 11:30:19 +01:00
tags: {value:"",validate:function(v) { return this.user == "dm" || v.length > 0;}},
2013-11-23 00:09:49 +01:00
user: {value:"false",required:true},
2013-10-09 21:18:09 +02:00
name: {value:""},
topic: {value:"tweets"}
2013-09-05 16:02:48 +02:00
},
inputs:0,
outputs:1,
icon: "twitter.png",
label: function() {
2013-11-24 17:48:24 +01:00
if (this.name) {
return this.name;
}
if (this.user == "dm") {
var user = RED.nodes.node(this.twitter);
return (user?user.label()+" ":"")+"DMs";
} else if (this.user == "user") {
return this.tags+" tweets";
}
return this.tags;
2013-09-05 16:02:48 +02:00
},
labelStyle: function() {
return this.name?"node_label_italic":"";
2013-11-23 00:07:08 +01:00
},
oneditprepare: function() {
$("#node-input-user").change(function() {
var type = $("#node-input-user option:selected").val();
if (type == "user") {
2013-11-23 22:48:17 +01:00
$("#node-input-tags-row").show();
2013-11-23 00:07:08 +01:00
$("#node-input-tags-label").html("User");
$("#node-input-tags").attr("placeholder","comma-separated @twitter handles");
2013-11-23 22:48:17 +01:00
} else if (type == "dm") {
$("#node-input-tags-row").hide();
2013-11-23 00:07:08 +01:00
} else {
2013-11-23 22:48:17 +01:00
$("#node-input-tags-row").show();
2013-11-23 00:07:08 +01:00
$("#node-input-tags-label").html("for");
$("#node-input-tags").attr("placeholder","comma-separated words, @ids, #hashtags");
}
});
$("#node-input-user").change();
2013-09-05 16:02:48 +02:00
}
});
< / script >
< script type = "text/x-red" data-template-name = "twitter out" >
< div class = "form-row" >
2014-09-03 16:11:10 +02:00
< label for = "node-input-twitter" > < i class = "fa fa-user" > < / i > Twitter< / label >
2013-09-05 16:02:48 +02:00
< input type = "text" id = "node-input-twitter" >
< / div >
< div class = "form-row" >
2014-09-03 16:11:10 +02:00
< label for = "node-input-name" > < i class = "fa fa-tag" > < / i > Name< / label >
2013-09-05 16:02:48 +02:00
< input type = "text" id = "node-input-name" placeholder = "Name" >
< / div >
< / script >
< script type = "text/x-red" data-help-name = "twitter out" >
2013-11-15 09:59:06 +01:00
< p > Twitter out node. Tweets the < b > msg.payload< / b > .< / p >
2014-09-01 11:15:25 +02:00
< p > If < b > msg.media< / b > exists and is a Buffer object, this node will treat it
as an image and attach it to the tweet.< / p >
2013-09-05 16:02:48 +02:00
< / script >
< script type = "text/javascript" >
RED.nodes.registerType('twitter out',{
category: 'social-output',
color:"#C0DEED",
defaults: {
twitter: {type:"twitter-credentials",required:true},
name: {value:"Tweet"}
},
inputs:1,
outputs:0,
icon: "twitter.png",
align: "right",
label: function() {
return this.name;
}
});
< / script >