Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUERY] Trigger Event filter out thread messages #309

Closed
gilhrpenner opened this issue Apr 25, 2024 · 15 comments
Closed

[QUERY] Trigger Event filter out thread messages #309

gilhrpenner opened this issue Apr 25, 2024 · 15 comments
Labels
backend Slack backend issue

Comments

@gilhrpenner
Copy link

Question

Hello! Am trying to work on an event trigger that listens for message reactions but I would like to filter out all events on a thread message, so if user reacts a given emoji on main message of a thread it proceeds and if the message is a thread reply then it halts.

Context

import {
  TriggerContextData,
  TriggerEventTypes,
  TriggerTypes,
} from "deno-slack-api/mod.ts";
import { Trigger } from "deno-slack-api/types.ts";
import "std/dotenv/load.ts";
import { MessageReactionsWorkflow } from "../workflows/message_reactions.ts";

const trigger: Trigger<typeof MessageReactionsWorkflow.definition> = {
  type: TriggerTypes.Event,
  name: "Message reaction listener",
  description: "Listen to specific message reactions and trigger a workflow",
  workflow: `#/workflows/${MessageReactionsWorkflow.definition.callback_id}`,
  event: {
    event_type: TriggerEventTypes.ReactionAdded,
    channel_ids: [Deno.env.get("PLATFORM_CHANNEL")!],
    filter: {
      version: 1,
      root: {
        operator: "OR",
        inputs: [
          { statement: "{{data.reaction}} == white_check_mark" },
          { statement: "{{data.reaction}} == eyes" },
          { statement: "{{data.reaction}} CONTAINS clock" },
        ],
      },
    },
  },
  inputs: {
    reaction: {
      value: TriggerContextData.Event.ReactionAdded.reaction,
    },
    message_context: {
      value: TriggerContextData.Event.ReactionAdded.message_context,
    },
    user_id: {
      value: "{{data.user_id}}",
    }
  },
};

export default trigger;

Environment

"deno-slack-sdk/": "https://deno.land/x/deno_slack_sdk@2.9.0/",
"deno-slack-api/": "https://deno.land/x/deno_slack_api@2.3.2/",
deno 1.42.4 (release, aarch64-apple-darwin)
v8 12.3.219.9
typescript 5.4.3
ProductName:		macOS
ProductVersion:		14.4.1
BuildVersion:		23E224
Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:49 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6020

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

@WilliamBergamin WilliamBergamin added the backend Slack backend issue label Apr 25, 2024
@WilliamBergamin
Copy link
Contributor

WilliamBergamin commented Apr 25, 2024

Hi @gilhrpenner thanks for writing in 💯

I tried to implement this in a few different ways, but I was not able to successfully filter out reactions made to messages in thread, this seems to be limitation/bug, I've queried about this internally in an attempt to find a workaround

@gilhrpenner
Copy link
Author

Hey @WilliamBergamin thanks for checking this

@gilhrpenner
Copy link
Author

Hey @WilliamBergamin any updates on this? Users reactions on thread messages are eating through my premium workflow usage lol

@WilliamBergamin
Copy link
Contributor

A fix for this should be coming in the near future but I don't have any real ETA

The only work around I've been able to gather seems to leverage the message_link attribute that does not seem to be documented, I have not had the time to test it out but the message_link value will only contain a thread_ts url param if the message is posted in a thread

Potentially a filter resembling something like {{data.message_link}} CONTAINS 'thread_ts='}} may work but I haven't had a chance to test this out idea out yet

@gilhrpenner
Copy link
Author

A fix for this should be coming in the near future but I don't have any real ETA

The only work around I've been able to gather seems to leverage the message_link attribute that does not seem to be documented, I have not had the time to test it out but the message_link value will only contain a thread_ts url param if the message is posted in a thread

Potentially a filter resembling something like {{data.message_link}} CONTAINS 'thread_ts='}} may work but I haven't had a chance to test this out idea out yet

Thanks @WilliamBergamin !! It sort of works now, I am able to filter out thread reactions but with a single emoji, haven't been able to have an OR operator together

filter: {
  version: 1,
  root: {
    operator: "AND",
    inputs: [
      {
        operator: "NOT",
        inputs: [{
          statement: "{{data.message_link}} CONTAINS thread_ts",
        }],
      },
      {
        operator: "OR",
        inputs: [
          { statement: "{{data.reaction}} == white_check_mark" },
          { statement: "{{data.reaction}} == eyes" },
          { statement: "{{data.reaction}} CONTAINS clock" },
        ],
      },
    ],
  },
},

2024-05-07 14:32:21 [error] [Wf070UBJPSJY] (Trace=Tr072SUCCPCZ) Trigger for workflow 'Message reactions workflow' failed: invalid_block

Am I doing this wrong or is it possibly a bug?

@WilliamBergamin
Copy link
Contributor

I've tried to implement this but I think the value of data.message_link turns out to be null,
I'm unsure why the failed: invalid_block error is coming up, I've also seen it during my testing

Currently trying to identify how to access the variable referred to the Link to message that was reacted to in the workflow builder

Let me know if you where successfully able to filter out messages from threads, this is the filter I was testing with

    filter: {
      version: 1,
      root: {
        operator: "AND",
        inputs: [
          {
            operator: "NOT",
            inputs: [{
              statement: "{{data.message_link}} CONTAINS thread_ts",
            }],
          },
          { statement: "{{data.reaction}} == eyes" },
        ],
      },
    },

@gilhrpenner
Copy link
Author

Hey @WilliamBergamin I was able to successfully filter out thread reactions, data.message_link is not being returned null for me.

Your filter works for me, it triggers the function when I react with 👀 on the main message.
The only issue is to be able to listen for multiple reactions

@WilliamBergamin
Copy link
Contributor

Hi @gilhrpenner the issue with the OR nested inside an AND is a bug on the backend, I am currently collecting more information on the bug

Thank you for bringing this forward 🙏

@WilliamBergamin
Copy link
Contributor

WilliamBergamin commented May 13, 2024

Hi @gilhrpenner thanks again for bringing this up, this was a bug and a patch has been shipped, I've tested it this morning and the nested OR in a AND operator works on my end 🙌

You may need to recreate your trigger, let me know if this resolves the issue

@gilhrpenner
Copy link
Author

Hi @gilhrpenner thanks again for bringing this up, this was a bug and a patch has been shipped, I've tested it this morning and the nested OR in a AND operator works on my end 🙌

You may need to recreate your trigger, let me know if this resolves the issue

Hey @WilliamBergamin, thanks for the follow up!
I just tried on my end and although I am not getting the failed: invalid_block error anymore I don't see my trigger function being called.

This is my filter

filter: {
      version: 1,
      root: {
        operator: "AND",
        inputs: [
          {
            operator: "NOT",
            inputs: [{
              statement: "{{data.message_link}} CONTAINS thread_ts",
            }],
          },
          {
            operator: "OR",
            inputs: [
              { statement: "{{data.reaction}} == white_check_mark" },
              { statement: "{{data.reaction}} == eyes" },
              { statement: "{{data.reaction}} CONTAINS clock" },
            ],
          },
        ],
      },
    },

If I remove the nested AND filter and have either NOT operator or OR it works fine but not both at the same time

@WilliamBergamin
Copy link
Contributor

Can you make sure that you've deleted and recreated your trigger this can be done with the following

slack trigger delete
slack trigger create

slack trigger update will not be sufficient

@gilhrpenner
Copy link
Author

Can you make sure that you've deleted and recreated your trigger this can be done with the following

slack trigger delete
slack trigger create

slack trigger update will not be sufficient

Yep, deleted and created the trigger, still not working

slack trigger delete
? Select a team digitalmga T8JU3LV0S
? Choose an app environment Local A0702H9CJEN
? Choose a trigger: Message reaction listener (local) Ft073XTYR4QG

🗑️  Trigger 'Ft073XTYR4QG' deleted

slack trigger create
? Select a team digitalmga T8JU3LV0S
? Choose an app environment Local A0702H9CJEN
⚡ Searching for trigger definition files under 'triggers/*'...
   Found 5 trigger definition files

? Choose a trigger definition file: triggers/message_reactions.ts

⚡ Trigger successfully created!

   Message reaction listener (local) Ft07391MHHL3 (event)
   Created: 2024-05-13 17:07:58 -06:00 (0 seconds ago)
   Collaborators:
     Gil Penner @Gil Penner U03SELC8YKD
   Can be found and used by:
     everyone in the workspace
   Hint:
     Invite your app to the channel to receive the events
   Warning:
     Slack Connect channels are unsupported

slack run
? Choose a local environment digitalmga T8JU3LV0S A0702H9CJEN
Updating local app install for "APOLLO"

⚡ Listing triggers installed to the app...

📆 Scheduled triggers:

   Daily job (local) Ft070BAW5YHM (scheduled)
   Created: 2024-04-25 19:44:16 -06:00 (2 weeks ago)
   Updated: 2024-05-06 23:10:14 -06:00 (6 days ago)
   Collaborators:
     Gil Penner @Gil Penner U03SELC8YKD
   Can be found and used by:
     everyone in the workspace

   Weekly job (local) Ft072N33MTDG (scheduled)
   Created: 2024-05-08 19:52:28 -06:00 (4 days ago)
   Collaborators:
     Gil Penner @Gil Penner U03SELC8YKD
   Can be found and used by:
     everyone in the workspace

🔗 Shortcut triggers:

   Request dev support (local) Ft070P0AVALD (shortcut)
   Created: 2024-04-25 19:43:18 -06:00 (2 weeks ago)
   Updated: 2024-05-03 10:52:49 -06:00 (1 week ago)
   Collaborators:
     Gil Penner @Gil Penner U03SELC8YKD
   Can be found and used by:
     everyone in the workspace
   https://slack.com/shortcuts/Ft070P0AVALD/e9673b20ca4350072f22a083c4fad453

   Manage tags (local) Ft072CSZ4LKX (shortcut)
   Created: 2024-05-07 22:17:50 -06:00 (5 days ago)
   Updated: 2024-05-07 22:54:57 -06:00 (5 days ago)
   Collaborators:
     Gil Penner @Gil Penner U03SELC8YKD
   Can be found and used by:
     everyone in the workspace
   https://slack.com/shortcuts/Ft072CSZ4LKX/0d220aaf360fb047b8dbb2082195cb80

I can't remember but shouldn't the trigger be listed under the "Listing triggers installed to the app..."?

@WilliamBergamin
Copy link
Contributor

I see, I was able to reproduce your behavior

This does not seem like we completely fixed the issue

@WilliamBergamin
Copy link
Contributor

@gilhrpenner Yesterday a patched was deployed this should now work as expected

Let me know if it works on your end, I'll mark this issue as resolved

@gilhrpenner
Copy link
Author

Hey @WilliamBergamin although I still can't see the trigger being listed under the trigger list I can confirm it's working!

Thank you so much for crushing this bug 🐛

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Slack backend issue
Projects
None yet
Development

No branches or pull requests

2 participants