Want to send Telegram Message if Window is open.
Problem: Whenever I add i.name to the Message (equal if only one or a List through a String) in openhab.log
[ab.action.telegram.internal.Telegram] Method failed: HTTP/1.1 400 Bad Request
and the Message isn’t send.
The Part of the Rule:
var String temp
temp=""
gWindow.members.filter[ i|i.state == OPEN ].forEach [i|
temp = temp + "\n" + i.name
]
logInfo("FB.rules", "Offen sind "+temp)
sendTelegram("Bot", "Folgende Fenster oder Türen sind noch offen:\n"+temp.toString)
sendMail("BLA@localhost", "Offene Fenster", "Offen sind "+temp)
That sendMail I added to see what should be send via Telegram for debugging only.
The Mail shows all right:
You add an \n, but the mail shows _. Are you sure this is the right code/mail content?
I’m using \n in telegram messages and have no problems. I can’t remember, but I’m sure that I also had _ in telegram messages. I can’t believe that this is the error.
Update: you use toString on a String. That’s not necessary.
Its the right code! The \n does a Line Feed before the Item-Names to list everyone in a different row. It the richt code / mail content!
I tried with “Bot”,“Text_Test” and got the same error.
After I used temp=temp.replace("_","-") it works!
It’s definitly the Underscore in the Item-Names
That .toString was while testing, after +temp didn’t work, but thanks for the hints.
Googling a bit shows that underscore _ and asterisk * have a markup/highlight function in Telegram.
Any system that wants a visible _ in telegram text seems to need to escape it in some way.
It’s arguable whether that should be up to the binding or the user in OH - you might want to invoke the markup function.
I think maybe you need to look into the telegram action parseMode configuration parameter - does that sort all this out?