Send image from local machine (not remote) using sendPhoto
See original GitHub issueContext
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
- Telegraf.js Version: 3.26.0
- Node.js Version: 8.11.3
- Operating System: Windows/OSX
Expected Behavior
Bot receives photo - OK Saved it to disk - OK Manipulate photo - OK Send it back
Current Behavior
I am building a bot that will receive photos, save them to the disk, watermark them and send them back.
Last step is my issue. I am trying to send a photo back to the user from my machine (Ubuntu/nginx). Home and user directory permissions are fine and the file exists.
I have tried:
var data = '';
var readStream = fs.createReadStream('cross.png', 'utf8');
readStream.on('data', function(chunk) {
data += chunk;
}).on('end', function() {
console.log(data);
bot.telegram.sendPhoto(testGroup, data);
});
Have also tried:
fs.readFile('cross.png', 'binary', function(err, data) {
if (err) throw err;
bot.telegram.sendPhoto(testGroup, data);
console.log(data);
});
Both work, I can see the file contents in the console, no matter what encoding I set - still a bit confused about this. But no file is being sent back to the user. I can’t make the folder public and use full urls.
Any ideas, please?
- Great work btw, I love Telegraf!
Failure Logs
Error: 400: Bad Request: wrong URL host
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
bot.telegram.sendPhoto(user.chatId, { source: FILE_PATH })
The current recommendation is:
Using
{ source }
will also work, butInput
helpers are guaranteed to work in future versions of Telegram while the underlying implementation changes.