slackapi / deno-slack-sdk

SDK for building Run on Slack apps using Deno
https://api.slack.com/automation
MIT License
165 stars 27 forks source link

[QUERY] Access message details in a workflow? #288

Closed mambuganarayana closed 7 months ago

mambuganarayana commented 7 months ago

Question How can I access the details entered by the user in my workflow?

Context I have an external application that sends a message to a next-generation Slack App using the chat.PostMessage API. The message contains interactive components (like text fields, radio buttons, etc.), including a button.

When the user enters information and clicks the button, I would like to save the details provided by the end-user into a Datastore.

I set the button with type equal to workflow as detailed here. However, the document says this button will not send 'block_actions' events as it is launching a new workflow.

My question is, how can I access the details entered by the user in my workflow?

Environment

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

deno 1.41.0 (release, aarch64-apple-darwin) v8 12.1.285.27 typescript 5.3.3

ProductName: macOS ProductVersion: 14.3.1 BuildVersion: 23D60 Darwin Kernel Version 23.3.0: Wed Dec 20 21:30:44 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6000

Requirements

WilliamBergamin commented 7 months ago

Hi @mambuganarayana thanks for writing in 💯

If I understand correctly your application has a workflow with a step that posts a message with a button to kicks off another workflow. An alternative could be to use an interactive message that contains a button scoped to a single step/function. This way you will have access to the entire context of the message.

Let me know if this answered your question

mambuganarayana commented 7 months ago

Thank you, @WilliamBergamin. Let me explain my use case.

I have two applications.

  1. Internal application. It is not a Slack application. Let's call it 'InternalApp.'
  2. Custom Slack application containing workflows, functions, and interactions with data stores. Let's call it 'SlackApp.' It is created using Slack CLI like this. It has a bot token.

The InternalApp sends an interactive message containing components (like text fields, radio buttons, etc.), including a button. To send the message, it uses a bot token of the 'SlackApp' and calls the HTTPS endpoint chat.postMessage.

The message appears in the 'Messages' tab of the SlackApp for the end user.

The user provides information (enters data into the text field, selects radio button options), and clicks on Submit button.

At this point, I want to trigger a workflow function associated with the SlackApp and pass all the information the user provided. Is this possible? If so, how?

The function then uses the information and inserts it into a data store.

seratch commented 7 months ago

Since the bot token provided by your workflow Slack app is not permanent / static, your non-Slack app cannot utilize the token for sending a message.

The InternalApp sends an interactive message containing components (like text fields, radio buttons, etc.), including a button. To send the message, it uses a bot token of the 'SlackApp' and calls the HTTPS endpoint chat.postMessage.

If your "internal" app needs the ability to send a message at a certain timing, here are two possible options:

  1. Create a new app at https://api.slack.com/apps just to allow your "internal" app to send a message to Slack; The message has a button with a link trigger URL to start a workflow
  2. Create a new app at https://api.slack.com/apps and do everything with the app (= no workflow)

With the option 1., the workflow triggered by the button click first opens a modal dialog to collect user inputs and relay the data to the next step. Here is an example code: https://github.com/slack-samples/deno-code-snippets/tree/main/Block_Kit_Modals

If you go with option 2., you can do everything within a single Bolt app: https://slack.dev/bolt-js

mambuganarayana commented 7 months ago

Thank you very much.

If your "internal" app needs the ability to send a message at a certain timing,

Yes, the flow starts from our internal app.

I will try out option#1.

Regarding option#2, I am assuming we need to expose a request URL that is accessible publicly OR make use of WebSockets. Is this correct?

For security reasons, we are not allowed to expose a public URL. I have tried WebSockets for development using Bolt SDKs. It works very well. Does Slack recommend it for production as well?

seratch commented 7 months ago

Yeah, you can go with either Request URL (publicly accessible URL) or Socket Mode (WebSocket protocol).

Does Slack recommend it for production as well?

Yes, we do. You can use Socket Mode for production use cases too. When your app needs more scalibility, you can run up to 10 instances for an app.

It seems that everything is clear now. Would you mind closing this issue?

mambuganarayana commented 7 months ago

Yes, Thanks again.!