First of all - THX Martin for all your efforts,
meanwhile i tried around a little more and succeeded in generating a working script

It is not elegant but there is enough room to improve it later...
This is my code:
Code: Select all
zeilen = split({notification_text_big }, "\\n");
wa = newList();
for (Zeile in zeilen)
{
wa = addElement(wa, Zeile);
}
muster = getElement(wa, 1);
wa_kurz = removeElementValue(wa, muster);
index = length(wa) - 1;
muster = getElement(wa, index);
wa_kurz = removeElementValue(wa, muster);
if (length(wa_kurz) > 3)
{
index = length(wa) - 1;
muster = getElement(wa, index);
wa_kurz = removeElementValue(wa, muster);
}
wa = reverse(wa);
if (length(wa)< 3)
{
text = getElement(wa, 0);
}
else
{
tex = getElement(wa,0);
tee = split(tex, ":");
if (length(tee)<2)
{
text = getElement(wa,0);
}
if (length(tee)>1)
{
text = getElement(tee,1);
}
}
Here is a little description:
zeilen = split({notification_text_big }, "\\n");
wa = newList();
for (Zeile in zeilen)
{
wa = addElement(wa, Zeile);
}
First the {notification_text_big} string is devided by lines and written in a list. It looks like this :
[WhatsApp, , CM12: Test1, Adc rhonin: Test 2, , , , , , …, 2 Nachrichten in 2 Chats.]
muster = getElement(wa, 1);
wa_kurz = removeElementValue(wa, muster);
From my tests i knew that the second element of the list with listindex 1 is always an empty field. Getting this pattern i delete all empty fields in the list.
index = length(wa) - 1;
muster = getElement(wa, index);
wa_kurz = removeElementValue(wa, muster);
From the tests i also know that the last list's entry is alway something with "Nachrichten" - messages which can also be deleted
if (length(wa_kurz) > 3)
{
index = length(wa) - 1;
muster = getElement(wa, index);
wa_kurz = removeElementValue(wa, muster);
}
If there are more than one message (the length of the resulting list is bigger than 3 elements) i have also to delete the last list's entry "...."
wa = reverse(wa);
if (length(wa)< 3)
{
text = getElement(wa, 0);
}
else
{
tex = getElement(wa,0);
tee = split(tex, ":");
if (length(tee)<2)
{
text = getElement(wa,0);
}
if (length(tee)>1)
{
text = getElement(tee,1);
}
}
In a last step i reverse the list to have the newest message on the first position of the list. If there is only one message the read text is identical with the first entry. If there are more than one message from ONE sender i could also read the first entry aloud. If there are more than one sender the entry looks like:
Sender: This is my message
So it must be devided again and this time the second entry in the new created list is read aloud.
The flow in which the script is used is triggered by the notification in the statusbar. Then first the ticker text is read aloud:
Message from Sender
After that TEXT from the script is read aloud
This is my message
To prevent double actions while 2 or more messages come in at nearly the same time i have to set the option
Wait until the actual running instance has been ended (or similar - i have the german version

)
Maybe i upload the flow later in the sharing area if someone is interested...
THX again
Rhonin