question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Send image from local machine (not remote) using sendPhoto

See original GitHub issue

Context

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:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

5reactions
Nikewekecommented, Feb 10, 2021

bot.telegram.sendPhoto(user.chatId, { source: FILE_PATH })

0reactions
MKRherecommented, Nov 25, 2022

The current recommendation is:

import { Input } from "telegraf";

bot.telegram.sednPhoto(chatId, Input.fromLocalFile("/path/to/file"));

Using { source } will also work, but Input helpers are guaranteed to work in future versions of Telegram while the underlying implementation changes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to send an image from a telegram bot - Stack Overflow
I have included two functions, one is good for sending local images, the other one is good for sending remote images. def sendImage():...
Read more >
ESP32-CAM Take and Send Photos via Email using an SMTP ...
Take and send captured photos from the ESP32-CAM to your email account using an SMTP Server. The last photo taken is temporarily saved...
Read more >
How to send photo to Telegram Bot via PowerShell using ...
Hi All,. I am trying to send screenshot to Telegram Bot from PowerShell, but unfortunately it is not working, I can't figure it...
Read more >
Send an image in the notification payload - Firebase - Google
With notification set as shown, this send request enables the receiving client to handle the image delivered in the payload. Was this helpful?...
Read more >
sendPhoto - Telegram Bot API - PHP SDK
Sending Photo Using Image URL ... The ability to send an image directly from a URL is also supported in the library. Instead...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found