line

Publish Slack messages to a Google Sheet

A workflow to pull all messages from a slack channel from a specific date and add them to a google sheet and then send a private message to a slack user when its complete.

Workflow Code

View the Github Project.. View all of the files, fork the project and deploy to Heroku in a few clicks. Or run it in the online sandbox without needing to install Zenaton.

Play on Zenaton

const slackConnectorId = "<ENTER_YOUR_ZENATON_SLACK_CONNECTOR_ID>";
const googlesheetsConnectorId = "<ENTER_YOUR_ZENATON_GOOGLE_SHEETS_CONNECTOR_ID>";

module.exports.handle = function*({channelToSource, channelToNotify, spreadsheetId}) {
  const slack = this.connector("slack", slackConnectorId);
  const google_sheets = this.connector("google_sheets", googlesheetsConnectorId);

  // Extract messages from a slack channel
  const history = (yield slack.get("channels.history", {
    query: {
      channel: channelToSource
    }
  })).data;

  const range = "sheet1!A:D";

  // Transform data to match GoogleSheet format
  const cells = history.messages.map(x => [x.user, x.text]);

  // Append data to a GoogleSheet
  yield google_sheets.post(
    `/${spreadsheetId}/values/${range}:append?valueInputOption=RAW`,
    {
      body: {
        range: range,
        majorDimension: "ROWS",
        values: cells
      }
    }
  );

  // Send a Slack message to the destination channel
  yield slack.post("chat.postMessage", {
    body: {
      text: "Done",
      as_user: false,
      channel: channelToNotify
    }
  });
};

Workflow Input

A workflow instance is launched with the following input.\ A workflow can be launched using the quick launch button on the sandbox or via http.

[
  {
    "channelToSource": "<ENTER_SLACK_CHANNEL_SOURCE",
    "channelToNotify": "<ENTER_SLACK_CHANNEL_DESTINATION",
    "spreadsheetId": "<ENTER_GOOGLE_SPREADSHEET_ID"
  }
]

Modify the workflow input

You will need to add the IDs of your slack channels and google spreadsheet in order to run the workflow.

Get the slack channel_id from the channel url.

slack channel id

Get the spreadsheet_id from the Google sheets url

google spreadsheet id

Click on "Workflow Input" in the sandbox to edit the input. The curl will also update.

sandbox workflow input

View the Github Project.. View all of the files, fork the project and deploy to Heroku in a few clicks. Or run it in the online sandbox without needing to install Zenaton.

Play on Zenaton