Hello everyone!
I wanted to try to get this working, as I currently have a slew of commands that work with my own hard-coded Telegram ID, although I have multiple people in my household, and occasionally a family member that visits and I’d like to try to implement a multiple-choice menu system via Telegram for some basic commands of primarily used lights and routines… (I have several implemented for me, either reminders when a certain thing is triggered with buttons that I can tap to select, or just warnings if certain doors aren’t latched shut etc, all of which works fine… just for me…)
I came up with the idea of a potential way to do this last night, but am having a hard time getting it to work so I’m hoping someone can help. I’m sure it’s due to the way I’m creating and passing variables.
All applicable Telegram ID’s have been added under my things file, so the bot will only accept messages from trusted users.
Under my telegram.rules file (I have about 650+ lines in it, but have snipped it down to just my concept code for interacting with multiple users.)
//Initiate variables
var String commandreplyid = null
var String commandreplyname = null
rule "Telegram Bot Commands"
when
Item telegramMessage received update
then
val telegramAction = getActions("telegram","telegram:telegramBot:Telegram_Bot")
var String botCommand = telegramMessage.state.toString.toLowerCase
//Hard-code the commandreplyid and commandreplyname based upon the most recent MessageUser.state
if(Telegram_MessageUser.state == "Username1"){
commandreplyid = "123456789"
commandreplyname = "Nickname1"
}
if(Telegram_MessageUser.state == "Username2"){
commandreplyid = "024680246"
commandreplyname = "Nickname2"
}
if(Telegram_MessageUser.state == "Username3"){
commandreplyid = "135791357"
commandreplyname = "Nickname3"
}
if(Telegram_MessageUser.state == "Username4"){
commandreplyid = "987654321"
commandreplyname = "Nickname4"
}
logInfo("telegram.rules", commandreplyid+", Name: "+commandreplyname+" Messaged.")
if (botCommand == "help"){
//Reply to user using previously hard-coded commandreplyid and commandreplyname
telegramAction.sendTelegram(commandreplyid, "Hi "+commandreplyname+"! Available Options: ...")
} else if (botCommand == "test"){
//Additional commands and actions, etc
}
//Reset variables back to null
commandreplyid = null
commandreplyname = null
end
the logInfo() bit echos the hard-coded variables commandreplyid and commandreplyname in the logfile no problem from the specified user who sends a message, but the telegramAction.sendTelegram() does not execute properly, and instead of saying “Hi Nickname1! Available Options: …” its just sending a single message of the user’s commandreplyid to all users.
It’s like the commandreplyid variable isn’t passing as a string to the telegramAction.sendTelegram() function, so instead of sending the specified message, it’s just sending the users id to everyone.
I’m stumped and can’t figure that part out.