Is it possible to use Workflows to save a query output as a CSV file and write the file to a Slack channel? If not, what other method could I use to create and export a CSV file using workflows?
Hey @madgleason! Could you try using our Papaparse library? I believe you could specifically use unparse: https://www.papaparse.com/#unparse
Once I've used Papa.unparse, how do I actually send the CSV as an attachment?
This is what I have right now but it doesn't work... any help is appreciated!
This is what I get in my Slack channel (it's blank)
Alternatively, and this might actually be more desirable, how can I send the SQL output formatted as a SQL table?
I tried using SQLBot but it requires a signup and I'm not getting my account confirmation, so an alternative approach would be much appreciated.
I've been trying to figure out how to do this myself for a while now. I finally figured it out today!
I'm doing it like this:
// Prepare the data for CSV conversion
// Note: Replace 'dataSource' with your actual data array variable
const dataForCsv = dataSource.map(row => ({
"Column 1 Name": row.column_1_data, // Replace 'Column 1 Name' with your desired column name and 'column_1_data' with its actual name from the data source
"Column 2 Name": row.column_2_data, // Replace 'Column 2 Name' with your desired column name and 'column_2_data' with its actual name from the data source
"Column 3 Name": row.column_3_data // Replace 'Column 3 Name' with your desired column name and 'column_3_data' with its actual name from the data source
// Add more columns as needed
}));
// Convert the prepared data to CSV format using PapaParse
// Note: Ensure PapaParse library is included in your project for CSV conversion
const csv = Papa.unparse(dataForCsv);
// Return the CSV content for further use
// This CSV content can be used in applications that require CSV format data
return csv;
Then, I'm making an api call to slack via a RESTQuery resource:
(When setting up your slack app for this , make sure to set the bot token scopes of: files:write, channels:join, and channels:write)
There are a few other slack body-form keys it can take. Api Ref is here
That's it! Hope it helps someone else!