Skip to content

Commit

Permalink
first code
Browse files Browse the repository at this point in the history
  • Loading branch information
valerio-vaccaro committed Aug 21, 2018
1 parent f9838e8 commit 47ace99
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# node-red-contrib-mastodon
Mastodon node for node-red platform, allow send and receive messages from your account on Mastodon.
Mastodon node for node-red platform, allow send and receive messages from your account on Mastodon.
9 changes: 9 additions & 0 deletions mastodon/getMessage.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
<label for="node-input-topic"><i class="fa fa-tag"></i> API url</label>
<input type="text" id="node-input-api_url" placeholder="https://mastodon.social/api/v1/">
</div>

<div class="form-row">
<label for="node-input-topic"><i class="fa fa-tag"></i>Hashtag</label>
<input type="text" id="node-input-tag" placeholder="tag">
</div>
</script>


Expand Down Expand Up @@ -57,6 +62,10 @@
api_url: {
value: "https://mastodon.social/api/v1/",
required: false
},
tag: {
value: "",
required: true
}
},
inputs: 1, // set the number of inputs - only 0 or 1
Expand Down
29 changes: 16 additions & 13 deletions mastodon/getMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ module.exports = function(RED) {
var access_token;
var timeout_ms;
var api_url;
var tag;
var node = this;

// Get varables from the node
this.access_token = n.access_token;
this.timeout_ms = n.timeout_ms;
this.api_url = n.api_url;
this.tag = n.tag;

var M = new Masto({
access_token: access_token,
Expand All @@ -47,20 +49,21 @@ module.exports = function(RED) {
});

this.on("input", function(msg) {
/*var id;
M.post('media', { file: fs.createReadStream('path/to/image.png') }).then(resp => {
id = resp.data.id;
M.post('statuses', { status: '#selfie', media_ids: [id] })
})*/
try {
/*M.post('statuses', {
status: msg.payload
});
this.status({
fill: "green",
shape: "dot",
text: "sent: " + msg.payload
});*/
M.get('timelines/tag/' + msg.payload.tag, {
local: false
})
.then(resp => {
console.log(resp.data);
msg = {};
msg.payload = resp.data;
this.status({
fill: "green",
shape: "dot",
text: "received: " + msg.payload
});
node.send(msg);
});
} catch (err) {
console.log(err);
}
Expand Down
12 changes: 6 additions & 6 deletions mastodon/sendMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

module.exports = function(RED) {
var Masto = require('mastodon')
const fs = require('fs');

function sendMessage(n) {
RED.nodes.createNode(this, n);
Expand All @@ -33,12 +34,6 @@ module.exports = function(RED) {
this.timeout_ms = n.timeout_ms;
this.api_url = n.api_url;

var M = new Masto({
access_token: access_token,
timeout_ms: timeout_ms, // optional HTTP request timeout to apply to all requests.
api_url: api_url, // optional, defaults to https://mastodon.social/api/v1/
});

// Status icon
this.status({
fill: "grey",
Expand All @@ -47,6 +42,11 @@ module.exports = function(RED) {
});

this.on("input", function(msg) {
var M = new Masto({
access_token: this.access_token,
timeout_ms: this.timeout_ms, // optional HTTP request timeout to apply to all requests.
api_url: this.api_url, // optional, defaults to https://mastodon.social/api/v1/
});
if (msg.payload.hasOwnProperty('image')) {
var id;
M.post('media', {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-mastodon",
"version": "0.0.3",
"version": "0.0.7",
"description": "Mastodon node for node-red platform",
"author": "Valerio Vaccaro <[email protected]>",
"dependencies": {
Expand Down

0 comments on commit 47ace99

Please sign in to comment.