shurillu / CTBot

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

Sending image and deleting messages #39

Open hernan3009 opened 4 years ago

hernan3009 commented 4 years ago

Hello,

I wish to know if there is any possibility of sending images and deleting messages form a chat.

My intentions are the following:

Thank you for sharing your project!

shurillu commented 4 years ago

Hello Hernan, thanks for using the library. Regarding your questions:

Thanks, cheers

Stefano

cgfoed commented 3 years ago

I think a small file transfer of a picture could be done with the ESP8266 but regardless it would be great if you could implement the /sendphoto command with the URL option. Shouldn't be tooo hard I guess? 😁 https://core.telegram.org/bots/api#sendphoto

Hence as a workaround I could store my picture with a separate device in the cloud, transfer the URL to the ESP and then send out the pic via CTBot using the URL.

shurillu commented 3 years ago

Hello cgfoed, have you tried the v3.0.0 branch? In that version I implemented some new functionalities, like sending binary data (images, documents etc). The only limit is that you need to have the media content to send stored locally (for example, stored in a connected SD card or acquired by a connected camera).

Regarding your question in detail, it's not so complicated to implement, I'll do when I find some time (in these weeks I'm overwelmed by work).

cgfoed commented 3 years ago

Hello cgfoed, have you tried the v3.0.0 branch? In that version I implemented some new functionalities, like sending binary data (images, documents etc). The only limit is that you need to have the media content to send stored locally (for example, stored in a connected SD card or acquired by a connected camera).

Regarding your question in detail, it's not so complicated to implement, I'll do when I find some time (in these weeks I'm overwelmed by work).

thanks for that detail and your work! highly appreciated. i'll give the 3.0.0 branch a try soon!

rahul4271 commented 3 years ago

I am also looking for deleting message which is sent by the bot if a certain action or condition completes. I loved this library thanks shurillu.

shurillu commented 3 years ago

Hello rahul4271 the functionality that you are looking for is already implemented in the v3.0.0 version. You can find it in the v3.0.0 branch, here

Cheers,

Stefano

rahul4271 commented 3 years ago

thanks for your reply, I am trying to auto-delete the message which I received from the bot so I trying to retrieve message-id of a particular message but I haven't found any way to return msg id. please try to update your examples for the v3.0.0 branch.

shurillu commented 3 years ago

Hello rahul4271, when I wrote the library, I added some self explaining comments in every header files as a guide. So, if you open the CTBot.h header file and look for the sendMessage() method you can find that:

...
    // send a message to the specified telegram user ID
    // params
    //   id      : the telegram recipient user ID 
    //   message : the message to send
    //   keyboard: the inline/reply keyboard (optional)
    //             (in json format or using the CTBotInlineKeyboard/CTBotReplyKeyboard class helper)
    // returns
    //   the messageID of the sent message if no errors occurred. Zero otherwise
    int32_t sendMessage(int64_t id, const char* message, const char* keyboard = "");
...

This mean that every time your bot send a message, you can get the related ID because the sendMessage() method returns that ID. You can store that ID and use it in the deleteMEssage() method:

...
    // delete a previously sent message
    // params
    //   id        : the telegram recipient/chat ID
    //   messageID : the message ID to be deleted
    // returns
    //   true if no errors occurred
    bool deleteMessage(int64_t id, int32_t messageID);
...

Hoping this can help, feel free to send me another message if not!

Cheers

Stefano