Skip to content

Commit

Permalink
support image & debug
Browse files Browse the repository at this point in the history
  • Loading branch information
valerio-vaccaro committed Aug 14, 2018
1 parent 4e3e078 commit f9838e8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion mastodon/getMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = function(RED) {
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({
Expand Down
31 changes: 20 additions & 11 deletions mastodon/sendMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = function(RED) {
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({
Expand All @@ -47,22 +47,31 @@ 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 {
if (msg.payload.hasOwnProperty('image')) {
var id;
M.post('media', {
file: fs.createReadStream(msg.payload.image)
}).then(resp => {
id = resp.data.id;
M.post('statuses', {
status: msg.payload.text,
media_ids: [id]
});
this.status({
fill: "green",
shape: "dot",
text: "sent: " + msg.payload.text
});
});
} else {
M.post('statuses', {
status: msg.payload
status: msg.payload.text
});
this.status({
fill: "green",
shape: "dot",
text: "sent: " + msg.payload
text: "sent: " + msg.payload.text
});
} catch (err) {
console.log(err);
}
});

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.2",
"version": "0.0.3",
"description": "Mastodon node for node-red platform",
"author": "Valerio Vaccaro <[email protected]>",
"dependencies": {
Expand Down

0 comments on commit f9838e8

Please sign in to comment.