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

[QUERY] App cannot reply in private channel given all_resources: true

Open tzuo9 opened this issue 11 months ago • 2 comments

Hi team,

I have set all_resources: true in my trigger and the app can start replying once it's invited to a public channel but the trigger is not working when i tag the app in private channel even if i add the bot. I saw no logging using slack activity --tail when i tag the app in private channel. Is this expected?

I found in doc that

Alternatively, you can set all_resources to true The channel_ids field will no longer be required, and the event will now trigger in all channels in the workspace the app is a part of.

wonder here what should i do if I want the bot be able to reply in private channel upon invitation

Thank you!

tzuo9 avatar Mar 17 '25 18:03 tzuo9

Hi @tzuo9 thanks for writing in 💯

I was able to reproduce this on my end using the following trigger

import { Trigger } from "deno-slack-sdk/types.ts";
import { TriggerEventTypes, TriggerTypes } from "deno-slack-api/mod.ts";
import SimpleWorkflow from "../workflows/simple_workflow.ts";

const appMentionedTrigger: Trigger<typeof SimpleWorkflow.definition> = {
  type: TriggerTypes.Event,
  name: "App mention trigger",
  description: "A sample trigger",
  workflow: `#/workflows/${SimpleWorkflow.definition.callback_id}`,
  event: {
    event_type: TriggerEventTypes.AppMentioned,
    all_resources: true,
  },
  inputs: {},
};

export default appMentionedTrigger;

I initially was not receiving any app_mentioned events in public or private channels, once I added a link trigger to trigger to my app then it started receiving app_mentioned events 🤔

I'm not sure how consistent this issue is but I raised this internally to try and figure out what is going on, you can also email our developer support team: [email protected] to inform them of this behavior

WilliamBergamin avatar Mar 17 '25 21:03 WilliamBergamin

@tzuo9 after further investigation I can not reproduce your behavior, everything seems to be working as expected on my end

Here is the app I've been using

// manifest.ts
import { Manifest } from "deno-slack-sdk/mod.ts";
import SampleWorkflow from "./workflows/sample_workflow.ts";

export default Manifest({
  name: "app-mention-as-a-trigger-1",
  description: "A template for building Slack apps with Deno",
  icon: "assets/default_new_app_icon.png",
  workflows: [SampleWorkflow],
  outgoingDomains: [],
  botScopes: [
    "commands",
    "chat:write",
    "chat:write.public",
    "app_mentions:read",
  ],
});
// workflows/sample_workflow.ts
import { DefineWorkflow, Schema } from "deno-slack-sdk/mod.ts";
import { SampleFunctionDefinition } from "../functions/sample_function.ts";

const SampleWorkflow = DefineWorkflow({
  callback_id: "sample_workflow",
  title: "Sample workflow",
  description: "A sample workflow",
  input_parameters: {
    properties: {
      channel: {
        type: Schema.slack.types.channel_id,
      },
      user: {
        type: Schema.slack.types.user_id,
      },
    },
    required: ["channel", "user"],
  },
});

const sampleFunctionStep = SampleWorkflow.addStep(SampleFunctionDefinition, {
  message: "hello",
  user: SampleWorkflow.inputs.user,
});

SampleWorkflow.addStep(Schema.slack.functions.SendMessage, {
  channel_id: SampleWorkflow.inputs.channel,
  message: sampleFunctionStep.outputs.updatedMsg,
});

export default SampleWorkflow;
// triggers/app_mentioned_trigger.ts
import { Trigger } from "deno-slack-sdk/types.ts";
import {
	TriggerContextData,
	TriggerEventTypes,
	TriggerTypes,
} from "deno-slack-api/mod.ts";
import SampleWorkflow from "../workflows/sample_workflow.ts";

const appMentionedTrigger: Trigger<typeof SampleWorkflow.definition> = {
	type: TriggerTypes.Event,
	name: "Sample trigger",
	description: "A sample trigger",
	workflow: `#/workflows/${SampleWorkflow.definition.callback_id}`,
	event: {
		event_type: TriggerEventTypes.AppMentioned,
		all_resources: true,
	},
	inputs: {
		channel: {
			value: TriggerContextData.Shortcut.channel_id,
		},
		user: {
			value: TriggerContextData.Shortcut.user_id,
		},
	},
};

export default appMentionedTrigger;
// functions/sample_function.ts
import { DefineFunction, Schema, SlackFunction } from "deno-slack-sdk/mod.ts";

export const SampleFunctionDefinition = DefineFunction({
  callback_id: "sample_function",
  title: "Sample function",
  description: "A sample function",
  source_file: "functions/sample_function.ts",
  input_parameters: {
    properties: {
      message: {
        type: Schema.types.string,
        description: "Message to be posted",
      },
      user: {
        type: Schema.slack.types.user_id,
        description: "The user invoking the workflow",
      },
    },
    required: ["message", "user"],
  },
  output_parameters: {
    properties: {
      updatedMsg: {
        type: Schema.types.string,
        description: "Updated message to be posted",
      },
    },
    required: ["updatedMsg"],
  },
});

export default SlackFunction(
  SampleFunctionDefinition,
  ({ inputs }) => {
    const updatedMsg = `:wave: ` + `<@${inputs.user}>` +
      ` submitted the following message: \n\n>${inputs.message}`;

    return { outputs: { updatedMsg } };
  },
);
  1. run slack run (install app and create the trigger)
  2. create a private channel
  3. Add the app to the channel
  4. Send @app-mention-as-a-trigger (local) hello to the channel
  5. The app responds as expected in the channel

If you're app is using addition configurations it may be interfering with the event dispatching

WilliamBergamin avatar Mar 20 '25 14:03 WilliamBergamin