slackapi / deno-slack-sdk

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

[QUERY] When Triggered Via Message Shortcut, Possible To Access Message Text, Send to External API, Then OpenForm (or views.open?) #321

Open jpaulgale opened 2 months ago

jpaulgale commented 2 months ago

Question

Upon message shortcut being triggered in a message, I am looking to

I can't seem to figure out how to A) access the message text in the workflow.ts B) send to the LLM prior to the OpenForm step

Thank you for your time!

Context

Documentation on slack.com is confusing to me inre: what is for Bolt vs what is for deno-slack-sdk.

I've created the app, gotten it to successfully send placeholder text (and text from OpenForm if I use that as the first step) to openai, but I cannot seem to access the message text or understand how to include a step prior to OpenForm, which is leading me to think views.open is the way, as per the below documentation:

https://api.slack.com/automation/forms https://api.slack.com/automation/interactive-messages https://api.slack.com/automation/interactive-modals#open-block-kit-action

Environment

cat import_map.json | grep deno-slack "deno-slack-sdk/": "https://deno.land/x/deno_slack_sdk@2.11.0/", "deno-slack-api/": "https://deno.land/x/deno_slack_api@2.4.0/",

deno --version deno 1.43.3 (release, aarch64-apple-darwin) v8 12.4.254.13 typescript 5.4.5

sw_vers && uname -v ProductName: macOS ProductVersion: 14.4.1 BuildVersion: 23E224 Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:25 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6030

zimeg commented 1 month ago

Hey @jpaulgale! 👋 Super interesting use case and this seems possible using a custom function and the built-in open form function!

I'd recommend the following flow with a few more workflow-related features if that's alright. It'll still requires an extra step before opening a modal, but after an LLM response is received:

  1. Start a workflow with a "reaction added" event trigger
  2. Add a custom function as the first step: a. As input, take the message_ts and channel_id from the event trigger b. Gather message contents using conversations.history with inclusive: true, limit: 1, latest: message_ts, and channel: channel_id c. Ask the LLM to perform the needed magic d. As output, return the task_name and due_date
  3. Send a message with interactive buttons using the built-in "send a message" step to prompt someone to fill out a form. I believe this works in thread or for ephemeral messages too, and is needed for the interactivity returned as an output.
  4. Use the "open form" step with the fields you want, defaults from step 2, and interactivity from step 3!
  5. Continue the workflow however you'd like!

This is suggested with more automation features in mind as the Deno SDK supports this well, but the same can be accomplished with other means of gathering message text and opening modals if that's preferred. Please let me know if this works for you or if you have other questions!