Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[telegram] sendTelegramPhoto should be more resilient #10807

Closed
Novanic opened this issue Jun 5, 2021 · 7 comments · Fixed by #11125
Closed

[telegram] sendTelegramPhoto should be more resilient #10807

Novanic opened this issue Jun 5, 2021 · 7 comments · Fixed by #11125
Labels
enhancement An enhancement or new feature for an existing add-on

Comments

@Novanic
Copy link
Contributor

Novanic commented Jun 5, 2021

I'm using telegram actions to send a photo when someone is ringing the doorbell. Sometimes it happens, that the event is triggered and the photo URL is available, but the photo isn't ready to download.

This error occurs in that case: "Download from https://... failed with status: 404".

That is fatal, because it causes that no telegram message is sent. It would be good when at least the message/caption from sendTelegramPhoto is sent without the photo. Or better: When the telegram action trys to sent it again 1 or 2 seconds later.

OpenHAB 3.0.2 is used.

This is my example rule:

rule "Doorbell ring"
when
Channel "netatmo:NAWelcomeHome:xy:welcomeHomeEvent" triggered INCOMING_CALL
then
val telegramAction = getActions("telegram","telegram:telegramBot:xy")
telegramAction.sendTelegramPhoto(WelcomeHome_SnapshotURL.state.toString, "Doorbell ring")
end

@Novanic Novanic added the enhancement An enhancement or new feature for an existing add-on label Jun 5, 2021
@Rapti
Copy link

Rapti commented Jun 8, 2021

You could try adding a few seconds of delay into your rule as a workaround.

rule "Doorbell ring"
     when
        Channel "netatmo:NAWelcomeHome:xy:welcomeHomeEvent" triggered INCOMING_CALL
    then
        val telegramAction = getActions("telegram","telegram:telegramBot:xy")
        createTimer(now.plusSeconds(3)) [|
            telegramAction.sendTelegramPhoto(WelcomeHome_SnapshotURL.state.toString, "Doorbell ring")
        ]
end

@Skinah
Copy link
Contributor

Skinah commented Jun 10, 2021

What happens if you call the URL for the photo multiple times in a normal web browser by pressing F5 for refresh? Do you get 404 if the same url is called multiple times?

@Skinah
Copy link
Contributor

Skinah commented Aug 10, 2021

Having read this again I understand what it is your asking, that a work around be implemented for when a camera or other source has a fault. I'm not sure what other peoples view is but there are a few ways forward.

  1. Log the fault only and send no message at all. Does it do this now?
  2. Try fetching again with a limit on how many re-trys to make. More involved to code.
  3. When fetching the photo, if it fails, send a normal message with no attachment and add to the end of the message that "photo failed to download".
  4. Take the stance that a user should fetch the photo to a variable, check the variable is not empty and then decide which message to send. If so perhaps add an example rule to the documentation.

What do others think? I probably support doing number 3.

@Skinah
Copy link
Contributor

Skinah commented Aug 18, 2021

Ok I have implemented option 3 for sending photos, videos and animations. Simply doing a delay in a rule as the example above given would not solve the issue. I see it as pointless making the code be overly complex when it could be the camera is doing a weekly reboot or be fully offline.

@Skinah
Copy link
Contributor

Skinah commented Aug 23, 2021

I will add another thing I discovered reading the code. That is it will return a boolean as false if the download fails..

var result = telegramAction.sendTelegramPhoto(WelcomeHome_SnapshotURL.state.toString, "Doorbell ring")

You can then check the result of the var to see if it is true or false and then use a delay/timer to retry.

@Novanic
Copy link
Contributor Author

Novanic commented Aug 30, 2021

Hello, thank you very much. That sounds like a very good solution (it is now guaranteed that a message is sent, there is hint in the message when the picture download failed and everybody can now also realize a retry function within a rule when desired). Perfect! :-)

I will test it soon. Will it be within the next 3.1.x version?

@Skinah
Copy link
Contributor

Skinah commented Aug 30, 2021

It should be in 3.2milestone2 and newer, this should be out very soon as in days. If you subscribe to the announcement category of the forum you will then get notified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature for an existing add-on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants