-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[Telegram action] enhancement: added send photo capability #3553
Conversation
parts[0] = new StringPart("chat_id", groupTokens.get(group) | ||
.getChatId()); | ||
parts[1] = new FilePart("photo", new ByteArrayPartSource( | ||
String.format("image.%s", imageType), imageFromURL)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest something like what I added to the mail action in order to use the actual file name from the URL, or fall back to a generic name:
String fileName = photoURL.replaceFirst(".*/([^/?]+).*", "$1");
fileName = StringUtils.isNotBlank(fileName) ? fileName : String.format("image.%s", imageType);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@watou
If you are suggesting to get the name from the url, in my opinion this is not a good idea.
The url usually is something like http://..../get.php?date=11122015&height=24&width=250&res=high&....
In general the content type of the image is sent along the http headers and not in the name itself.
My code makes an analysis of the actual bytes received in order to guess the content type received, so that the telegram is happy with the file extension. And the name itself is not used by telegram apart from getting the extension, it is there just because required from the ByteArrayPartSource.
If you make a "save as" from telegram desktop the actual filename proposed is not the sent one but it is something like 83456634889_1232656545353543282341.jpg
So in my opinion my approach is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, your correct use of the file name extension to match the image type will make the generic "image" name unimportant to users. This is a different scenario from attaching any arbitrary file to an email, where the name can actually matter. Thanks for the detailed response.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
Tested sending a jpg photo from my mobotix cam! Very fast usefull!!! Thanks @paolodenti for your great work |
Will a 2-second HTTP timeout be sufficient if the user attempts to send a very, very large image? Aside from that question, this PR lgtm. |
@watou Thanks for the very useful suggestion. Do you want me to squash the 2 commits? |
@watou I squashed the 2 commits into 1 Thanks |
[Telegram action] enhancement: added send photo capability
Thanks @paolodenti! |
Added method to send pictures to Telegram.
Pictures are downloaded from a URL and sent to Telegram
An optional caption can be added to the picture.
Can be used to send surveillance systems screenshots.
Usage example
The third parameter (caption) can be null (no caption is sent)