slackapi / deno-slack-sdk

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

[FEATURE] Add `--output string` flag to `slack trigger list` (or even globally) #282

Open NathanHRich opened 6 months ago

NathanHRich commented 6 months ago

I have a bunch of lingering event triggers that I've created programmatically that I need to clean up. I'd like it to be easier to do this programmatically. I've noticed the --output string flag is available for slack datastore query. That's what I'm looking for, but for triggers.

When running the slack trigger list command, I've noticed there is a JSON response in the logs. It looks like the CLI then iterates over the triggers in that initial response to get additional info about users, permissions, etc. It would be great if I were able to supply an output flag or output file to dump the initial JSON body to. i.e. slack trigger list --type event --limit 1000 --team TEAM_ID --app APP_ID --output json or --output_file triggers.json

Really almost every Slack CLI command I've used appears to have a JSON response in the logs, having a global --output string flag would be excellent 🔥

Alternative solutions

I was able to find a workaround by hitting the API endpoint listed in the logs. Using a token generated with slack auth token

POST https://slack.com/api/workflows.triggers.list?token=SLACK_TOKEN
Headers: Content-Type application/json
Body: {"app_id":"APP_ID","limit":1000,"type":"event"}

I would expect this endpoint to be documented at https://api.slack.com/methods/workflows.triggers.list, but at the time of writing this, it's not. So keep that in mind if using this workaround.


More details about my use-case: I have a workflow that creates an event trigger to monitor a specific thread. Messages in that thread get passed to our ticketing management system through the triggered workflow. Upon trigger creation, I store the trigger id, along with some other info, in a Slack datastore. When the ticket is closed, the trigger and related datastore entry both get deleted. As with any solution, things slip through the cracks. That's where this cleanup task I'm working on comes in. My solution gets all the tickets in the datastore, checks their status in our ticketing system, and cleans up the trigger and datastore entry if certain conditions are met.

zimeg commented 6 months ago

Hey @NathanHRich! This is such a great request. I totally agree that having consumable outputs would make scripting tasks like this much easier, but I'm glad to hear you've found a workaround for now. Pretty clever, poking into the debug logs 😉

I'll share this with the team and hope to return with an update soon! Thanks a ton for sharing your use case with this request!