Help seperating variable

Post your questions and help other users.

Moderator: Martin

Post Reply
evebrea
Posts: 116
Joined: 12 Aug 2013 15:28

Help seperating variable

Post by evebrea » 01 Jun 2019 01:39

this is gonna be odd, but i have a flow i made that reads my messages on trillian messenger and discord via {notification_text}

but here's the kicker, if i my smartwatch isn't connected (speaker) i don't want it to read the whole message. I'd like to get just the name of the person sending the message, and have , for example "incoming discord message from Princess popo"

now this should be possible i think, i just don't know the right variable/function to use, which is why i'm asking for help.

the {notification_text} seems to get this format


Princess popo
but i don't want carrots for dinner

With a obvious "line break" in every test i've run, so while it's not using an "character", like colon, comma, semicolon, it IS separating the message from the name, ion the case of discord AND trillian messenger.

SO i'm looking for a way to make automagic see that line break, and say "global_incomingname = part before the line break" so it can then reed out "incoming discord message from princess popo"

Can someone help me with this?

actually after typing this out i looked at my test which is also getting {content_title} and that may be where the name is.. it looks like for each message i got someone else's name was saved in {content_title} on discord and trillian...

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Help seperating variable

Post by Desmanto » 01 Jun 2019 19:17

Do you still need the message part? Or you have solved it, since you only need the name part?
If you still need the message part, you can replace out the name {content_title} from the {notification_text}

Code: Select all

message = replace(notification_text, content_title, "");
message = trim(message);
This will replace the name in the notification text to "" (blank). Then trim it to remove the extra new line char.

Or as my habit, I will try to use regex as much as possible, to keep sharpening my regex skill.

Code: Select all

find = findAll(notification_text, "(.+\\n)((?s:.*))", true);
sender = find[0][1];
message = find[0][2];
Regex explanation :
(.+\\n) >> will match the sender name. .+ will match at least one char, of course the name must at least have it. Then \\n to match the line break
((?s:.*)) >> (?s:.*) will match any char including line break. The flags ?s: is to tell anything after the : (colon) to match using the new flag s (match \n too). So .* now will match newline too. The extra bracket () is to make sure it is categorized as second grouping.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply