jorisvddonk / node-red-contrib-discord

Node-red nodes that allow you to interact with Discord.
15 stars 19 forks source link

Images in the payload? #8

Closed flamingm0e closed 3 years ago

flamingm0e commented 6 years ago

Is there any way to send a binary buffer through from an HTML call? I have a notification that goes and grabs a camera still shot and sends it to telegram, but I would like to be able to do this with Discord.

jorisvddonk commented 6 years ago

Hi! Sorry for the extremely late response; I've been moving to another country and this issue slipped through the cracks :)

There's currently no way of doing this, and the way this works in Discord.js makes it somewhat difficult to integrate well with Node-RED without potentially breaking things. Node-RED sort of requires messages to be JSON-encodable, otherwise things like splitting, joining and duplicating messages doesn't work correctly. Discord.js's message structures aren't JSON-encodable, so for proper support I'd have to come up with my own intermediate message format which is then handled completely by the discordSendMessage node.

Maybe there's another easier way of doing it, though.. I'd have to look into it in a bit more detail.

nate8199 commented 5 years ago

For others searching for this, it works now by settting the msg.attachment to the file/URL location.

Here's my function I use to request a webcam image on output 1, waits 2 seconds then sends it to discord on output 2

var channel = msg.channel.id;

msg1 = {payload: "GET"} node.send([msg1, null]) node.status({fill:"blue", shape:"ring", text:'taking pic'});

setTimeout(function(){ node.status({fill:"green", shape:"ring", text:"sent"}); msg2 = {payload: 'Here it is', attachment:"/file/picture.jpg", channel: {id : channel}}; node.send([null, msg2]); }, 2000);

node.on('close', function() { // tidy up any async code here - shutdown connections and so on. });