u/UnkleMike

▲ 1 r/tasker

Google Messages Notifications and Tasker's Notification Removed Event

I've been working on the third iteration of my Notification Reminder project for the past few months and it seems pretty solid right now, with one notable exception: dealing with messages from multiple senders in a group thread in Google Messages.

Basically, the project is intended to provide recurring audible/vibrating reminders for selected notifications that I haven't acknowledged yet. Unique notification parameters, along with an assigned priority, are stored in a global array when a selected notification is received. As long as matching elements exist in this array, the reminder task is periodically launched. When a notification is cleared/removed, the matching array element (if any) is removed from the global array.

The problem I'm having is that for Google Messages, if a message is received from Joe Smith in a group thread, and a message in the same group thread is subsequently received from Bob Johnson, details from both notifications are added to the array, but once the group thread is opened in Google Messages, both notifications are cleared, but the only Notification Removed event triggered in Tasker is the one corresponding to the message from Bob Johnson. This causes the global array element for the message from Joe Smith to remain in the array, and the periodic reminder to continue, even though the message itself has been read.

Before I start trying to work around this behavior, I want to see if anyone else experiences the same behavior with Google Messages notifications, and see if anyone sees any issues with my code that would be related to the issue.

        Profile: Google Messages - Clear v3
    Variables: [ %debug:has value ]
    Event: Notification Removed [ Owner Application:Messages, Messages Title:* Text:* Subtext:* Other Text:* Cat:* ]
    
    
    
    Enter Task: Anon
    Settings: Run Both Together
    
    A1: If [ %debug Set ]
    
        A2: Parse/Format DateTime [
             Input Type: Now (Current Date And Time)
             Output Format: yyyy-MM-dd-HH:mm:ss
             Formatted Variable Names: %now
             Output Offset Type: None ]
    
        A3: Write File [
             File: Tasker/Google Messages.log
             Text: ---- Cleared ---- %now
             %evtprm(+%charLF)
             
             
             Append: On ]
    
    A4: End If
    
    A5: Multiple Variables Set [
         Names: %app,%title,%text,%subtext,%other,%cat,%pri
         Variable Names Splitter: ,
         Values: %evtprm(+%charTAB)
         Values Splitter: %charTAB
         Structure Output (JSON, etc): On ]
    
    A6: Variable Set [
         Name: %notification_string
         To: %app,%title
         Structure Output (JSON, etc): On ]
    
    A7: Variable Set [
         Name: %idx
         To: %nrNotifications(#?~R^[0-9],\Q%notification_string\E$)
         Structure Output (JSON, etc): On ]
    
    A8: If [ %idx neq 0 ]
    
        A9: Array Pop [
             Variable Array: %nrNotifications
             Position: %idx ]
    
        A10: Write File [
              File: Tasker/Google Messages.log
              Text: idx = '%idx' - matching notification found
              Append: On
              Add Newline: On ]
            If  [ %debug Set ]
    
    A11: Else
    
        A12: Write File [
              File: Tasker/Google Messages.log
              Text: idx = '%idx' - no matching notification found
              Append: On
              Add Newline: On ]
            If  [ %debug Set ]
    
    A13: End If
    
    A14: Variable Set [
          Name: %idx
          To: %nrNotifications(#?~R^[0-9],\Q%notification_string\E$)
          Structure Output (JSON, etc): On ]
    
    A15: If [ %debug Set ]
    
        A16: If [ %idx eq 0 ]
    
            A17: Write File [
                  File: Tasker/Google Messages.log
                  Text: pop successful
                 
                 
                  Append: On ]
    
        A18: Else
    
            A19: Write File [
                  File: Tasker/Google Messages.log
                  Text: pop failed
                 
                 
                  Append: On ]
    
        A20: End If
    
    A21: End If
    
    
    Profile: Google Messages - Set v3
    Variables: [ %priority_groups:has value %debug:has value ]
    Event: Notification [ Owner Application:Messages, Messages Title:* Text:* Subtext:* Messages:* Other Text:* Cat:msg New Only:Off ]
    
    
    
    Enter Task: Anon
    Settings: Run Both Together
    
    A1: If [ %debug Set ]
    
        A2: Parse/Format DateTime [
             Input Type: Now (Current Date And Time)
             Output Format: yyyy-MM-dd-HH:mm:ss
             Formatted Variable Names: %now
             Output Offset Type: None ]
    
        A3: Write File [
             File: Tasker/Google Messages.log
             Text: ---- Created ---- %now
             %evtprm(+%charLF)
             
             
             Append: On ]
    
    A4: End If
    
    A5: Multiple Variables Set [
         Names: %app,%title,%text,%subtext,%messages,%other,%cat,%new
         Variable Names Splitter: ,
         Values: %evtprm(+%charTAB)
         Values Splitter: %charTAB
         Structure Output (JSON, etc): On ]
    
    A6: If [ %text neq Sensitive notification content hidden ]
    
        A7: Simple Match/Regex [
             Type: Regex
             Text: %title
             Regex: ^((?<group>.*)?(: ))?(?<sender>.+)$ ]
    
        A8: Variable Set [
             Name: %message
             To: %text
             Structure Output (JSON, etc): On ]
    
    A9: Else
    
        A10: Simple Match/Regex [
              Type: Regex
              Text: %title
              Regex: ^(?<sender>.+): (?<message>.+)$ ]
    
    A11: End If
    
    A12: If [ %sender ~R [A-Za-z] ]
    
        <urgent>
        A13: Perform Task [
              Name: isContactInGroup
              Priority: %priority
              Parameter 1 (%par1): %sender
              Parameter 2 (%par2): %priority_groups
              Return Value Variable: %urgent
              Structure Output (JSON, etc): On ]
    
        <normal>
        A14: Perform Task [
              Name: isContactInGroup
              Priority: %priority
              Parameter 1 (%par1): %sender
              Parameter 2 (%par2): my contacts
              Return Value Variable: %normal
              Structure Output (JSON, etc): On ]
    
        <ignore>
        A15: Perform Task [
              Name: isContactInGroup
              Priority: %priority
              Parameter 1 (%par1): %sender
              Parameter 2 (%par2): ignore
              Return Value Variable: %ignore
              Structure Output (JSON, etc): On ]
    
    A16: End If
    
    A17: If [ %urgent eq true ]
    
        A18: Variable Set [
              Name: %pri
              To: 2
              Structure Output (JSON, etc): On ]
    
    A19: Else
        If  [ %normal eq true ]
    
        A20: Variable Set [
              Name: %pri
              To: 1
              Structure Output (JSON, etc): On ]
    
    A21: End If
    
    A22: Variable Set [
          Name: %notification_string
          To: %app,%title
          Structure Output (JSON, etc): On ]
    
    <only push if not a message reaction, the priority is set, there's no existing array entry for the title, and we're not ignoring this contact>
    A23: Array Push [
          Variable Array: %nrNotifications
          Position: 1
          Value: %pri,%notification_string ]
        If  [ %message !~R %messageReactionRegex & %pri Set & %nrNotifications(#?~R^[0-9],\Q%notification_string\E$) eq 0 & %ignore neq true ]

Note: %charTAB value is a TAB character (defined in another task/profile that runs on device boot), %messageReactionRegex value is (?s).+ “.+” (a regular expression used to identify iOS/RCS message reactions), %priority_groups is a simple pattern matching string, for example my family/my doctors.

reddit.com
u/UnkleMike — 20 hours ago