cotestatnt / AsyncTelegram2

Powerful, flexible and secure Arduino Telegram BOT library. Hardware independent, it can be used with any MCU capable of handling an SSL connection.
MIT License
83 stars 25 forks source link

Caption #85

Closed navdeepssidhu closed 1 year ago

navdeepssidhu commented 1 year ago

Hi, thanks for providing excellent Lib. This is not an issue only a request. Is it possible to add caption to picture sent to telegram bot? Thanks

navdeepssidhu commented 1 year ago

or show timestamp on picture

navdeepssidhu commented 1 year ago

or is it possible to show time stamp on the picture

cotestatnt commented 1 year ago

HI @navdeepssidhu At the moment you can send a picture with caption only from external url, but it is not a limitation of library itself, only my forgetfulness.

The needs of users who use a Telegram bot are many and it is difficult to predict them all from the beginning. For this reason, the Github issues are a valuable source of feedback and suggestions for which I thank you.

I will add the ability to add a caption to the picture (which can therefore also be a timestamp) as soon as I have some time to dedicate to the library!

cotestatnt commented 1 year ago

@navdeepssidhu it was easier than I thought because I had already foreseen the possibility, but leaved unimplemented. It was enough to make the caption an option parameter for sendPhoto() methods.

On this occasion I updated the sendPhoto.ino example. You can find the changes in latest release 2.1.4

navdeepssidhu commented 1 year ago

Thank you so much for your quick work. I will give it a go. Is a timestamp on picture itself possible?

cotestatnt commented 1 year ago

If you intend to merge the timestamp with the image, no it's not possible just using the Telegram API.

You have to use caption field for this purpose.

   ....
  time_t now = time(nullptr);
  struct tm sysTime= *localtime(&now);
  char timestamp[20];

  // https://cplusplus.com/reference/ctime/strftime/
  strftime(timestamp, sizeof(timestamp), "%d/%m/%Y - %T", &sysTime);

  // sendPhoto(const TBMessage &msg, const char* filename, fs::FS &fs, const char* caption = nullptr)
  myBot.sendPhoto(msg, "/telegram-bot1.jpg", FILESYSTEM, timestamp);
  ...
navdeepssidhu commented 1 year ago

Thanks a ton for updating the example.