Hey guys,
I am having trouble with Emojis in Telegram after using .split().
My Rule uses an item that contains user/group and message split by ;:
rule “Telegram-Gateway”
when
Item Telegram_Gateway received update
then
val String User = Telegram_Gateway.state.toString.split(’;’).get(0)
val String Msg = Telegram_Gateway.state.toString.split(’;’).get(1)
When I am sending the follwing message via command-cli, the Gateway-message is pure text whereas the testing message contains the lock-emoji (https://charbase.com/1f512-unicode-lock): openhab> smarthome:send Telegram_Gateway "userxxx;\ud83d\udd12"
Escaping does not work. Just leads to non-parsing of emojis in the testing message.
I added a screenshot: 3rd line is parsed like in the example above, 4th line is hardcoded like in the xample above. Line 1 and 2 are escaped like you mentioned. It changes nothing with the parsed message, but does not parse the emoji in the hardcoded example anymore.
Are you just seeing a problem because you bang off two telegrams within a millisecond? It doesn’t seem like a fair test; I would add a little delay while diagnosing, probably makes no difference but why have doubts.
I think it might be helpful to see if your substring is really unicode - two characters - or ascii
rule “Telegram-Gateway”
when
Item Telegram_Gateway received update
then
val String User = Telegram_Gateway.state.toString.split(’;’).get(0)
val String Msg = Telegram_Gateway.state.toString.split(’;’).get(1)
logInfo("Telegram-Gateway", "Msg chars: " + Msg.length)
val String Timestring = now.toString("dd.MM.YY' 'HH:mm:ss")
val String Message = "[" + Timestring + "] " + Msg
logInfo("Telegram-Gateway", "User: " + User + " | Msg: " + Message)
sendTelegram(User, Message)
Thread::sleep(500)
sendTelegram("userxxx", "[" + Timestring + "] " + "\ud83d\udd12")
end
Whatever parses sendTelegram( ... + "\ud83d\udd12")
actually parses it I suspect, it reads character \ character u character d etc. and ends up with a string containing two unicode characters.
The string manipulation results in a string containing 12 chars, \ u d etc. which looks like "\ud83d\udd12" of course but is not unicode.
I appears if you give sendTelegram(someString) a string variable, it uses the string as it is.
If however you give sendTelegram("literal") a string literal, something (and I’m guessing it is rules DSL not the command) parses the literal, where it recognises and encodes the unicode.
What you would like is an encodeStringAsUnicode function to work on your string before passing to telegram. Sounds simple, but I’ve no idea how to do that.