in general my TelegramBinding seems to configured well and also works in sending Messages. Now I started to implement some kind of conversation in rules.
I send a question to two chats (me and my girlfriend) via sendTelegramQuery: “Is the trash-can already brought out?”, “YES”, “NO”
When I answer from my Phone the message is received, handled and the sendTelegramAnswer removes the buttons
When my girlfriend answers, the message is received, handled, but the sendTelegramAnswer throws the Invalid-Query error and the buttons are still there.
I had the same problem. My workaround was to send a message to each participant of the group and handle their responses individually. You can do that by passing a ChatId (Long!) as first argument (e.g. myChatId) and modifying the Reply name accordingly (e.g. my_Reply_TrashCan) in the sendTelegramQuery action:
telegramAction.sendTelegramQuery(myChatId,"INFO: Ist der/die/das " + Abfall_next_event_name.state.toString + " bereits rausgestellt?", "my_Reply_TrashCan", "JA", "NEIN")
telegramAction.sendTelegramQuery(herChatId,"INFO: Ist der/die/das " + Abfall_next_event_name.state.toString + " bereits rausgestellt?", "her_Reply_TrashCan", "JA", "NEIN")
Of course that implies checking which participant has sent an answer in the answer handling rule:
rule "CALENDAR_Check_Next_Event_my_Reply"
when
Item TelegramBotHuman__ReplyId received update my_Reply_TrashCan
then
if (TelegramBotHuman_Last_Message__Text.state.toString == "JA") {
Global_Trash_Notification.sendCommand(ON)
telegramAction.sendTelegramAnswer(myChatId,TelegramBotHuman__ReplyId.state.toString, "Vielen Dank")
} else {
Global_Trash_Notification.sendCommand(OFF)
telegramAction.sendTelegramAnswer(myChatId,TelegramBotHuman__ReplyId.state.toString, "Na dann aber schnell!")
}
end
rule "CALENDAR_Check_Next_Event_her_Reply"
when
Item TelegramBotHuman__ReplyId received update her_Reply_TrashCan
then
if (TelegramBotHuman_Last_Message__Text.state.toString == "JA") {
Global_Trash_Notification.sendCommand(ON)
telegramAction.sendTelegramAnswer(herChatId,TelegramBotHuman__ReplyId.state.toString, "Vielen Dank")
} else {
Global_Trash_Notification.sendCommand(OFF)
telegramAction.sendTelegramAnswer(herChatId,TelegramBotHuman__ReplyId.state.toString, "Na dann aber schnell!")
}
end
To my understanding the first participant answering a group query consumes the queryId, so that an ulterior answer cannot be associated with the original query any longer.
@jalm: thanks for that hint - that solution worked. Only restriction: when he answers, her Buttons don’t get removed and vice versa - but I can deal with it
I had a similar problem, but with the query in a group chat. I could solve it by adding the Chat-ID in front of the reply-id. Maybe this could help you, too, or anybody else.
// Warnung beim Verlassen des Hauses, wenn noch Geräte aktiv sind
rule "Warnung aktive Geräte beim Verlassen"
when
Item Anwesenheitserkennung changed to OFF or
Item Test_Bot_Question changed to ON
then
if ((Aktive_Geraete_WZ.state == ON) || (Group_All_Licht.state == ON)) {
val telegramAction = getActions("telegram","telegram:telegramBot:Telegram_Bot")
telegramAction.sendTelegramQuery(-123456789L,"Es ist niemand mehr anwesend, aber noch Geräte oder Leuchten aktiv. Sollen alle Geräte und Leuchten ausgeschaltet werden?", "Warn_active_devices", "Ja", "Nein")
}
end
rule "Reply handler for Warning active devices"
when
Item telegramReplyId received update Warn_active_devices
then
val telegramAction = getActions("telegram","telegram:telegramBot:Telegram_Bot")
if (telegramMessage.state.toString == "Ja") {
Scenes_Heimkommen.sendCommand(OFF)
telegramAction.sendTelegramAnswer(-123456789L,telegramReplyId.state.toString, "Es wurden alle Geräte und Leuchten ausgeschaltet.")
}
if (telegramMessage.state.toString == "Nein") {
telegramAction.sendTelegramAnswer(-123456789L,telegramReplyId.state.toString, "Ok, es wurde keine Aktion durchgeführt.")
}
else {
telegramAction.sendTelegramAnswer(-123456789L,telegramReplyId.state.toString, "Keine passende Antwort erhalten.")
}
end