witnessmenow / Universal-Arduino-Telegram-Bot

Use Telegram on your Arduino (ESP8266 or Wifi-101 boards)
MIT License
1.12k stars 307 forks source link

send .txt file #181

Open droidprova opened 4 years ago

droidprova commented 4 years ago

Hello and thank you for the precious work you do. I noticed that you are working on updating this fantastic library. I have a request for you: is it possible to add a function that allows you to send a .txt file stored on an SD card? Exactly how it happens for photos? Thanks so much

witnessmenow commented 4 years ago

Will take a look if I have time.

solcer commented 4 years ago

Hello and thank you for the precious work you do. I noticed that you are working on updating this fantastic library. I have a request for you: is it possible to add a function that allows you to send a .txt file stored on an SD card? Exactly how it happens for photos? Thanks so much

You can also use telegramOta example for send files into spiffs.

droidprova commented 4 years ago

Hi, could you please see an example. Thank you

solcer commented 4 years ago

Hi, could you please see an example. Thank you Hi,

You can use telegramOTA.ino code for esp32. it is under the examples/Untested inc Upgrade/ESP32/telegram OTA/ folder.

if you send files with "write spiffs" caption, the code will write your file into to spiffs. If you send spiffs.bin file with "update spiffs" caption: it writes spiffs image to spiffs section. If you send firmware.bin file with "update firmware" caption: it updates firmware.

Besst

PoriadnyyOleg commented 3 years ago

Hi! To send a .txt file stored on an SD card by this library need some changes: Make a copy of sendPhotoByBinary and change string: String response = sendMultipartFormDataToTelegram("sendPhoto", "photo", "img.jpg", to String response = sendMultipartFormDataToTelegram("sendDocument", "document", "file.txt", I tried it, it works and sends me a "file.txt". Also i change "file.txt" to new input variable String& fileName.

akil1947 commented 1 year ago

Hi! To send a .txt file stored on an SD card by this library need some changes: Make a copy of sendPhotoByBinary and change string: String response = sendMultipartFormDataToTelegram("sendPhoto", "photo", "img.jpg", to String response = sendMultipartFormDataToTelegram("sendDocument", "document", "file.txt", I tried it, it works and sends me a "file.txt". Also i change "file.txt" to new input variable String& fileName. can you please elaborate on this. If possible please give me the full code

PoriadnyyOleg commented 1 year ago

add in .h : String sendDocumentByBinary( const String& chat_id, const String& contentType, int fileSize, MoreDataAvailable moreDataAvailableCallback, GetNextByte getNextByteCallback, GetNextBuffer getNextBufferCallback, GetNextBufferLen getNextBufferLenCallback, const String& fileName);

add in .cpp: String UniversalTelegramBot::sendDocumentByBinary( const String& chat_id, const String& contentType, int fileSize, MoreDataAvailable moreDataAvailableCallback, GetNextByte getNextByteCallback, GetNextBuffer getNextBufferCallback, GetNextBufferLen getNextBufferLenCallback, const String& fileName) {

ifdef TELEGRAM_DEBUG

Serial.println(F("sendDocument: SEND Document"));

endif

String response = sendMultipartFormDataToTelegram("sendDocument", "document", fileName, contentType, chat_id, fileSize, moreDataAvailableCallback, getNextByteCallback, getNextBufferCallback, getNextBufferLenCallback);

ifdef TELEGRAM_DEBUG

Serial.println(response);

endif

return response; }

akil1947 commented 1 year ago

@PoriadnyyOleg thank you so much for your help!