mast/telegram-bot-api

Buffer in sendPhoto

macsmac opened this issue · 1 comments

I need to send photo from buffer. Example:

api.on("message", function(msg) {
	if (msg.text == "/photo") {
		var canvas = new Canvas(512, 512);
		var ctx = canvas.getContext("2d");

		ctx.fillStyle = "#fff";
		ctx.fillRect(0, 0, 512, 512);

		ctx.fillStyle = "#000";
		ctx.fillRect(128, 128, 512 - 128, 512 - 128);

		api.sendPhoto({
			chat_id: msg.chat.id,
			caption: "...",
			photo: canvas.toBuffer()
		});
	}
});

Can it be done on current version?

mast commented

in 2.0 you use readable stream for photo property. You can convert buffer to readable stream.
https://stackoverflow.com/questions/13230487/converting-a-buffer-into-a-readablestream-in-node-js