deno-slack-api icon indicating copy to clipboard operation
deno-slack-api copied to clipboard

[BUG] export TriggerFilterDefinition to allow for dynamic filter building

Open mfcarroll opened this issue 9 months ago • 1 comments

The deno-slack versions

    "deno-slack-sdk/": "https://deno.land/x/[email protected]/",
    "deno-slack-api/": "https://deno.land/x/[email protected]/",

Deno runtime version

deno 2.1.9 (stable, release, aarch64-apple-darwin)
v8 13.0.245.12-rusty
typescript 5.6.2

OS info

ProductName:		macOS
ProductVersion:		15.2
BuildVersion:		24C101
Darwin Kernel Version 24.2.0: Fri Dec  6 19:02:41 PST 2024; root:xnu-11215.61.5~2/RELEASE_ARM64_T6030

Describe the bug

Steps to reproduce

import { Trigger } from "deno-slack-sdk/types.ts";
import {
  TriggerContextData,
  TriggerEventTypes,
  TriggerTypes,
} from "deno-slack-api/mod.ts";
import workflowDef from "../workflows/standbot_text.ts";
import { phrases } from "../internals/phrases.ts";

const textConditions = [];

for (const phrase of phrases) {
  const textCondition = {
    statement: `{{data.text}} CONTAINS '${phrase.text}'`,
  };
  textConditions.push(textCondition);
}

const standbotText: Trigger<typeof workflowDef.definition> = {
  type: TriggerTypes.Event,
  name: "Standbot Text",
  description: "Handles phrases",
  workflow: `#/workflows/${workflowDef.definition.callback_id}`,
  event: {
    event_type: TriggerEventTypes.MessagePosted,
    // channel_ids: ["C08CVGPD3KJ"], // #sandbox1
    all_resources: true,
    filter: {
      version: 1,
      root: {
        operator: "OR",
        inputs: textConditions,
      },
    },
  },
  inputs: {
    channelId: { value: TriggerContextData.Event.MessagePosted.channel_id },
    messageTs: { value: TriggerContextData.Event.MessagePosted.message_ts },
    text: { value: TriggerContextData.Event.MessagePosted.text },
  },
};

export default standbotText;

Expected result

No deno-ts error, because the type I've created it assignable, or the ability to import the correct type definition.

Actual result

The code works just fine, but generates a deno-ts error:

Type '{ type: "event"; name: string; description: string; workflow: "#/workflows/standbot_text"; event: { event_type: "slack#/events/message_posted"; all_resources: true; filter: { version: number; root: { ...; }; }; }; inputs: { ...; }; }' is not assignable to type 'ValidTriggerTypes<SlackWorkflowDefinitionArgs<{ channelId: { type: "slack#/types/channel_id"; }; messageTs: { type: "slack#/types/message_ts"; }; text: { type: "string"; }; }, ParameterSetDefinition, ("channelId" | "messageTs" | "text")[], PossibleParameterKeys<...>, "standbot_text">>'.
  Types of property 'event' are incompatible.
    Type '{ event_type: "slack#/events/message_posted"; all_resources: true; filter: { version: number; root: { operator: "OR"; inputs: { statement: string; }[]; }; }; }' is not assignable to type 'ChannelEvents | WorkspaceEvents'.
      The types of 'filter.root' are incompatible between these types.
        Type '{ operator: "OR"; inputs: { statement: string; }[]; }' is not assignable to type 'TriggerFilterDefinition'.
          Types of property 'inputs' are incompatible.
            Type '{ statement: string; }[]' is not assignable to type '[TriggerFilterDefinition, ...TriggerFilterDefinition[]]'.
              Source provides no match for required element at position 0 in target.deno-ts(2322)

What I'd like to do (I think)...

...
import { TriggerFilterDefinition } from "deno-slack-api/typed-method-types/workflows/triggers/trigger-filter.ts";

const textConditions: TriggerFilterDefinition[] = [];

for (const phrase of phrases) {
  const textCondition: TriggerFilterDefinition = {
    statement: `{{data.text}} CONTAINS '${phrase.phrase}'`,
  };
  textConditions.push(textCondition);
}
...

...only that's not possible because the definition isn't exported.

Hopefully I'm not just making an error or missing a better way to accomplish this. Like I said, the app works fine as written, which is what makes me think this is an sdk issue. Thanks!

mfcarroll avatar Mar 14 '25 19:03 mfcarroll

At first glance this seems like a reasonable enhancement 💯

I would like to look into it a bit more before making the change, to make sure we are not exporting something that could be subject to change in the near future

WilliamBergamin avatar Mar 17 '25 13:03 WilliamBergamin