CTBot icon indicating copy to clipboard operation
CTBot copied to clipboard

Sending image and deleting messages

Open hernan3009 opened this issue 5 years ago • 8 comments

Hello,

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

My intentions are the following:

  • Capture images with a cam (for an alarm system) and upload it to a Telegram Group.
  • Using that Telegram Group to control many devices from a NodeMCU. That said, having a history of actions of the users does not look clean.

Thank you for sharing your project!

hernan3009 avatar Jan 12 '20 19:01 hernan3009

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

  • probably sending images is too much for an ESP8266. I wondering too, but I guess (in a future) I'll migrate the library to the ESP32 board;
  • deleting messages is a functionality that I never evaluated! I'l put in the "to do" list.

Thanks, cheers

Stefano

shurillu avatar Jan 13 '20 07:01 shurillu

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.

cgfoed avatar Mar 31 '21 08:03 cgfoed

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).

shurillu avatar Apr 01 '21 05:04 shurillu

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!

cgfoed avatar Apr 01 '21 08:04 cgfoed

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.

rahul4271 avatar Apr 18 '21 13:04 rahul4271

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

shurillu avatar Apr 18 '21 13:04 shurillu

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.

rahul4271 avatar May 10 '21 07:05 rahul4271

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

shurillu avatar May 11 '21 20:05 shurillu