Hi,
as mentioned earlier in some thread I started working on a Telegram Binding. As a byproduct, I had to customize the existing Telegram action from @paolo_denti
Example command for the action:
var String json_keyboard = '{"inline_keyboard":[[{"text":"Erledigt","callback_data":"trash_done"},{"text":"Erinnere mich nochmal.","callback_data":"trash_later"}]]}'
sendTelegram("BiergartenBot", "%s und %s solltest du noch raus stellen.", json_keyboard, gCal_Abfall_Event1_Summary.state.toString, gCal_Abfall_Event2_Summary.state.toString)
Creates this:
(Translation: Bring the trash out: [Done] [Remember me again])
It is easy to ingegrate e.g. item names into the JSON string
This JSON is also possible and would create a little different keyboard:
'{"keyboard":[["opt 1","opt 2","opt 3"],["menu"]]}'
See here https://core.telegram.org/bots/api#replykeyboardmarkup ff
Example rule for the binding:
rule "New Telegram message: trash_done"
when
Item TelegramLasteMessageDate received update
then
if(TelegramLasteMessageDText.state.toString == "trash_done"){
Abfall_Steht_An.postUpdate(OFF)
}
end
The binding for now uses this library https://github.com/rubenlagus/TelegramBots.
The rules is triggerd when a new message (from given ChatID) is received.
Configuration of the binding:
You have to put the name and the token of your bot and your ChatID into the Thing configuration. The binding only accepts messages from the give ChatID
Thinks I want to do:
- Add multiple ChadIds (havenât found out yet how to read the
multiple="true"
configâŠ) - Find a better solution to trigger a new Message in the rule
- Shrink the sice of the binding
- alot(!) of testing and overall code clearing
- âŠ
Sooo, If you like download the JARs and placed them in your addons folder.
Feedback is very welcome! It was a fun journey so far and I dont want to stop it now.
Download:
https://drive.google.com/drive/folders/17jW8zK2ZHLUGTAqS_ai7kfjZAYsrf3Cg
Before I had some problems, ignore from here:
Based on a timer and an item, a rule triggers and sends me a message over Telegram that should look like this:
âYou have to take the trash out today.
[Done.] [Remember me later.] [Its not necessary today.]â
Depending on the answer openHAB does different things. In this example, it would change an item state or send another message after 10 Minutes.
I followed this tutorial https://www.openhab.org/docs/developer/development/ide.html and started developing.
So first of all, as a byproduct, I had to customize the existing Telegram action from @paolo_denti
It now accepts an additional optional JSON-String Parameter to create the custom keybord. Syntax is shown here: https://core.telegram.org/bots/api#replykeyboardmarkup ff
At second I followed this tutorial https://www.openhab.org/docs/developer/development/bindings.html#choosing-a-namespace and created my very first binding. It for now uses this library https://github.com/rubenlagus/TelegramBots.
Despite my rusty java skills this was somehow the easy part.
Both the Action and the Binding are working fine when openHAB is started via Eclipse. The Action can send different custom keyboards and the Binding gets messages send to the bot (whether from a custom keyboard or not).
There is plenty of work to do and I have quite some ideas what could be done, but the very basics are working when started via Eclipse.
I want to test things on my productive environment (openHABian) but this is where I stuck.
I exported the JAR via Eclipse (right click -> export -> JAR -> Finish), placed the JAR file in the addons folder and restarted openHAB. But I can see the Binding anywhere in the PaperUI.
If I export with the âGenerate the Manifest fileâ-option checked in the last step I get the following warning:
JAR export finished with warnings. See details for additional information.
org.openhab.action.telegram/META-INF/MANIFEST.MF was replaced by the generated MANIFEST.MF and is no longer in the JAR.
Is there anything I am missing? If it helps I can upload my (not working!) JAR.
Any feedback to the general idea of this Binding (and Action) is also very welcome.