0
votes

I have code that returns me image resource ( it's GD library) like imagepng($this->image);.

And Telegram method sendPhoto.

Please, help me >< what can I do with this resource to send it to Telegram?

Documentation says

"Photo to send. Pass a file_id as String to send a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload a new photo using multipart/form-data. More info on Sending Files ยป"

But I can't understand what I should make with this resource

1
Please check how to ask question and Minimal, Complete, and Verifiable example Add your code , what have you tried - and - sendPhoto sends photo. check input_type - Morse

1 Answers

0
votes

Method sendPhoto has 2 required fields - a chat_id, which is usually a user id, and a photo. You can specify photo using one of 3 following options:

  • URL of the photo (for example https://telegram.org/img/t_logo.png)
  • if you have previously sent your image, you can specify its file_id. This option does not make any sense if your bot sends a particular image only once. You can obtain file_id from photo property of Message object (when you send photo using sendPhoto method, the server returns Message).
  • or you can simply send a photo in HTTP request body using header Content-Type: multipart/form-data.

The easiest way is to send by URL.
The fastest way is to send by file_id, because telegram servers do not have to process incoming images. That's probably the reason why Telegram API marks it as the recommended option.


So if have a URL of the image, send it by URL or by file_id. If you have a file, send it as multipart/form-data payload.