Introduction
Slack commands are a powerful way to automate tasks and workflows using interactions in Slack. When coupled with Google Cloud Functions to execute the specific tasks, it forms a perfect combo to create interactive end-to-end workflows for simple and complex tasks. In this article we will dive on why we started using Slack commands and the bullet-proof architecture we have set in place to implement it.
The Problem Statement
On a weekly basis we draw an agenda on Google Sheets listing topics we plan to talk about on LinkedIn via our Astrafy account and we assign authors to those topics (i.e. Astrafy employees). We encountered a challenge of efficiently notifying and reminding team members about their tasks. We recognize the importance of not only automating the notification process but also ensuring a mechanism that would alert an admin in case of errors during the process (for instance, if no placeholder document had been created for the author to write his/her post). Furthermore, we needed a solution that would allow the admin to rectify the issues and re-run the notification process via Slack, seamlessly integrating human intervention when necessary. It is on this very point that we leveraged Slack commands; in case of a missing element for the post to be written, an admin would receive a Slack message with actions to correct and a “clear” button. When actions are corrected, pushing on this “clear” button would trigger a specific Cloud Function.
The Solution: Interactive Slack Commands with Cloud Function
Architecture Overview:
The solution comprises two primary components:
A private Cloud Function
A public Cloud Function
Security aspect
Security is always key in every solution we develop. Given that Slack cannot directly trigger a private Cloud Function, we had to come up with another safe mechanism which includes a proxy public Cloud Function depicted above.
This public Cloud Function can be invoked by anyone and the key to ensuring the security of our system lies in making sure that only requests originating from our Slack app are allowed to trigger our private Cloud Function. To ensure this, the public Cloud Function includes a request verification function that examines incoming requests from Slack. If the request is validated as originating from our Slack app, it is then permitted to trigger the private Cloud Function.
The diagram below demonstrates how the public Cloud Function works (inspired by this workflow from the Slack documentation):
Cloud Function structure and code
We use Google Cloud function second generation and as mentioned above we have two Cloud Functions:
Cloud Function #1 (Private Cloud function):
Trigger: Directly from Cloud Scheduler or from the Public Cloud Function
Purpose: Dispatch task reminder to team members via Slack
Process:
- Pulls task details from a Google Sheet file.
- Sends a Slack message with task information, including a hyperlink.
- If no hyperlink is provided, it alerts the admin a Slack message including a “Done” button.
Cloud Function #2 (Public Cloud function):
Trigger: Manually
Purpose: Verify incoming requests and trigger the private Cloud Function if requests originate from Slack.
Process:
- Checks if the request source is from Slack.
- If the request is verified as originating from Slack, it triggers the private Cloud Function.
You can see below our code snippet the request verification function:
Conclusion
In this article, we’ve journeyed through the innovative integration of interactive Slack commands with Cloud Functions, a fusion that redefines the landscape of internal workflows. The possibilities are boundless, and for us, it’s been a groundbreaking way to inject dynamism into our routine operations.
But it’s more than just about efficiency. Our foray into this integration has been a testament to the power of simplicity and timeliness. Tasks are now streamlined, organized, and executed with precision, thanks to this cutting-edge solution. And let’s not overlook the security aspect — it’s not just reliable, it’s fortress-level secure.
The real kicker? The speed of development with Cloud Functions. We are talking about turbocharging your automation features, getting them up and running in mere hours. It’s not just a change; it’s an evolution in how we handle our key workflows.
We are now starting to automate many of our routine tasks with slack commands and Cloud Function. And you, what are you waiting for ?
Thank you
If you have any questions or encounter any issues while applying this solution, let us know. We are open to discussion and here to help.
If you enjoyed reading this article, stay tuned as we regularly publish articles on handy solutions to automate your daily processes using Google Cloud ecosystem. Follow Astrafy on LinkedIn to be notified for the next article ;).
If you are looking for support with Google Cloud or Data Stack solutions, feel free to reach out to us at sales@astrafy.io.