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

Is there a way to trigger a Workflow from the command listener? #2301

Open
alexkfong opened this issue Oct 24, 2024 · 2 comments
Open

Is there a way to trigger a Workflow from the command listener? #2301

alexkfong opened this issue Oct 24, 2024 · 2 comments
Labels
auto-triage-stale question M-T: User needs support to use the project

Comments

@alexkfong
Copy link

alexkfong commented Oct 24, 2024

Hi, I'm trying to learn how to work with the Slack API.

Ultimately, I'm hoping to use my Bolt app to handle complex automations that are beyond the scope of the Workflow options within Slack itself. I'm currently just poking around to understand what's possible.

Right now, I'm trying to figure out if a slash command can start a workflow/automation that was created in app. The documentation I've seen suggests using triggers and workflow actions, but I'm trying to avoid having to create actual custom workflow steps since what I'm trying to do are workspace-specific, not organization-wide, automations.

@slack/bolt version

"@slack/bolt": "^3.22.0"

Your App and Receiver Configuration

const app = new App({
  token: process.env.SLACK_BOT_TOKEN,
  signingSecret: process.env.SLACK_SIGNING_SECRET,
  socketMode: true,
  appToken: process.env.SLACK_APP_TOKEN,
  port: process.env.PORT || 3000,
});

Node.js runtime version

v16.20.2

Steps to reproduce:

// Listen for slash command, which may come with parameters
app.command('/slashCommand', async ({ ack, payload, client, say }) => {
    try {
      const { channel_id, user_id } = payload;

      await ack();

      // Tell the user we're doing something
      await client.chat.postEphemeral({
        channel: channel_id,
        user: user_id,
        text: 'OK, beginning action!',
      });

     // In this spot run code, such as parsing data passed in as a parameter with the slash command

     // START AN EXISTING WORKFLOW HERE. I KNOW THIS WON'T WORK, BUT THIS IS THE IDEA:
     await response({
       user: user_id,
       {
          type: workflow,
          workflow: // hard-coded workflow ID taken from Slack app
       }      
     });

Expected result:

What I want to happen is a slash command automatically begins a workflow generated within the app.

@seratch seratch added question M-T: User needs support to use the project and removed untriaged labels Oct 24, 2024
@seratch
Copy link
Member

seratch commented Oct 24, 2024

Hi @alexkfong, thanks for asking the question.

I'm trying to figure out if a slash command can start a workflow/automation that was created in app

Unfortunately, you cannot do this. The workflow platform is designed to run workflows only through a trigger, such as a link, event, schedule, or webhook. Currently, there's no plan to enable slash commands as a trigger. For this use case, it's recommended to use a link/shortcut trigger. As long as the link trigger URL is not shared outside a specific workspace, the workflow won't be executed by other users within the same organization. However, I understand that this may not be secure enough for your needs, as the URL can be shared through a Slack Connect channel or for other reasons.

An alternative approach is to use an incoming webhook trigger. Your app.command listener can send a request to the webhook URL with pre-defined JSON data inputs. In this way, you can control how a workflow can be triggered.

I'm trying to avoid having to create actual custom workflow steps since what I'm trying to do are workspace-specific, not organization-wide, automations.

For Enterprise Grid organizations, we understand that this can be an obstacle when a workflow creator wants to narrow the user scope for running workflows. In this case, here are some workarounds I can suggest:

  1. Trigger a workflow on a different external workflow engine from the app's slash command listener.
  2. Implement a workflow either within your Bolt app or in your custom code.

The second one may not fit your use case, but if the workflow requires user inputs and runs a few steps under the hood, implementing it with Bolt would be relatively easy. Something like this: app.command listener to call views.open API to open a modal -> app.view listener to receive/validate user inputs -> start the workflow operation -> send a DM to confirm its completion.

I hope this was helpful to you.

Copy link

👋 It looks like this issue has been open for 30 days with no activity. We'll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-triage-stale question M-T: User needs support to use the project
Projects
None yet
Development

No branches or pull requests

2 participants