slackapi / slackapi/deno-slack-api

[BUG] export TriggerFilterDefinition to allow for dynamic filter building

Open
#120 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement semver:minor
Dominant language
TypeScript
Stars
45
Forks
18
PR merge metrics
No merged PRs in 30d

Description

The deno-slack versions

    "deno-slack-sdk/": "https://deno.land/x/deno_slack_sdk@2.15.0/",
    "deno-slack-api/": "https://deno.land/x/deno_slack_api@2.8.0/",

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!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction and inspect typed-method-types/workflows/triggers/trigger-filter.ts, along with the package's public exports. Run the shown Deno TypeScript check to confirm the tuple/type error. Done means the trigger filter type can be imported or the demonstrated filter assignment type-checks without an error.

Written by the indexing model from the issue text.

Assessment

Tech stack
deno, typescript
Domain
api, developer-experience
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.