shurillu / CTBot

A simple (and easy to use) Arduino Telegram BOT Library for ESP8266/ESP32
MIT License
147 stars 34 forks source link

Pictures or documents #100

Open rubentey opened 1 year ago

rubentey commented 1 year ago

If I use a ESP32 Camera Module. How can I add a picture in a sending message? Or send a document like a PDF? I haven't seen an example in the documentation. Maybe it's already implemented but I am bit blind reading. Thanks a lot for this really good project!

shurillu commented 1 year ago

Hello rubentey, thank you for using the library. If you download the version 3.0.0 form the v3.0.0 branch here there are losts of new functionalities, like sending text/binary files. With this version, you can send images by using these two member functions:

    bool sendImage(int64_t id, uint8_t* data, uint32_t dataSize);
    bool sendImage(int64_t id, File fhandle, uint32_t dataSize);

You can use the first one if you have the image already in RAM (in your case, you can capture the image from the sensor, then send it by calling the member function passing the image pointer and the size in bytes). Pay attention that the dataSize parameter is the size of the data pointed by the parameter data (it is a pointer).

Let me know if it helps.

Cheers,

Stefano

G-Remo commented 1 year ago

Hello, when I try to send document, for less than 40MB it work but I want more . Am I too optimist ??

@@ rubentey In my case it s ok from psram for send directly from espcam to telegram.

--->sendCommand: Payload {"limit":1,"allowed_updates":"[\"message\",\"callback_query\"]","offset":0} --->receive: HTTP Response OK: HTTP/1.1 200 OK --->receive: Content-Length size: 289 --->receive: start payload: {"ok":true,"result":[{"update_id":, "message":{"message_id":132403,"from":{"id":,"is_bot":false,"first_name":"GOT","last_name":"666","language_code":"fr"},"chat":{"id":,"first_name":"GOT","last_name":"666","type":"private"},"date":1667144341,"text":"photo"}}]} --->receive: end payload --->parseResponse: response received --->POST: Remaining data to send: 177929834 ////// --->POST: Remaining data to send: 173555306 --->POST: error sending HTTP payload (0/8192) --->sendBinaryData: Header POST https://api.telegram.org/bot/sendDocument HTTP/1.1 Host: api.telegram.org Content-Length: 177930120 Content-Type: multipart/form-data; boundary=----CTBotFormBoundary1357924680

It never fail at the same point but ever between 175000000 ~173000000 i try sendrawdata and sendbinary I try diferent PACKET_SIZE , sdcard block size... ESP32CAM AI THINKER esp32 2.0.5 ctbot 3.0.0

Merci

shurillu commented 1 year ago

Hello GOT666-Cyber, nice to hear that someone is trying to push limits far beyond :-D I never tried file bigger than 4MB, so I have to test it. BTW Telegram says that you can upload max 2GB so your 170MB should be allowed. Have you tried to increase the PACKET_SIZE to 16K (16384)? Actually I'm a bit busy (I'm moving) so I don't know when I can do some tests. Let me know if the packet size trick works.

Cheers

Stefano

G-Remo commented 1 year ago

Thanks for reply I try :: //#define CTBOT_PACKET_SIZE 16384

define CTBOT_PACKET_SIZE 8192 // bytes (8k)

//#define CTBOT_PACKET_SIZE 4096 //#define CTBOT_PACKET_SIZE 1024 //#define CTBOT_PACKET_SIZE 512

The file don't upload fully, it fail veyry quick "error sending HTTP payload (0/8192)" When it fail i lost definetly bot to telegram connection i should reset( ESP.restart) the esp32. I try with sendRawDataEx and it freeze