How to Build a Serverless Slack Command in minutes
Commander is a Slack app that provides a framework for developers to create custom serverless slash commands and serverless Slack apps without leaving the Slack environment. Commander is an app that simplifies your workflow to build custom apps. The commands which are created using Commander are serverless commands which run on Nimbella’s Serverless Cloud. There's nothing to install, no servers to manage, and no services you need to provision. Simplifying the process of creating Apps and slash commands allows you to quickly create or install functionality for your team to more efficiently communicate with each other.
Serverless computing with functions fundamentally reduces the amount of code you develop and deploy for cloud applications, eschewing the “server” parts, and allowing you to focus on just your functions. For a cloud-native application, where functions are APIs, an integrated API gateway handles the routing of events and REST requests to your functions.
The advantage of Commander is minimal configuration setup, easier development & deployment, and sharing across your team. Not only that but with Commander you also get access control, built-in security, and logging and all within Slack itself. These are unique and important features for small and large Slack teams alike, and we will describe them in our next article in the series.
What are slash commands?
According to Slack, “Slash Commands allow users to invoke your app by typing a string into the message composer box. A submitted Slash Command will cause a payload of data to be sent from Slack to the associated app. The app can then respond in whatever way it wants using the context provided by that payload. These commands are the entry points for complex workflows, integrations with external services, or even just simple message responses. They're the knock at your app's front door that could be the start of a great conversation”.
Install the Commander Slack app from the Slack App Directory or Nimbella’s Website.
After Installation, you should see the following message.
We have extensive documentation for Nimbella Commander and the slash commands it provides. Commander comes with the “/nc” slash command (short for Nimbella Commander). This command is used to create, manage, and run your custom commands. This is also the primary command to interact with the Commander.
Commands and what you can do with them
For Commander, commands are serverless functions which are invoked using Slack’s slash command. Commander allows you to create your own commands. Try it by typing /nc command_create demo to create a command named demo as shown below. The command is created with a stub function which you can immediately run with the command /nc demo. The stub function outputs a placeholder response which you can edit by clicking the shown “edit the code” link.
It’s that simple! We just created a serverless function and ran it on slack with just a single command. The content of the command is shown below, but the cool thing now is, it’s just upto your imagination to decide what you want your command to do.
You can also create commands which can take multiple arguments as shown below. If the arguments are not sent in the command, Commander automatically handles the error for you.
Command Set Registry, a home for all the commands
We showed above how easy it is to create a serverless command in slack. Now, normal use cases would require you to create multiple commands and what if you want to share it with everyone including your team? Enter, Command-Sets.
Command-sets are a way for you to group related commands under a single command-set. We have created a large number of command-sets and made it available on Github for public use. We call it “Command Set Registry”. Anyone can install, run and modify the commands under the command-set and the way to do it would be using “csm” or command-set-management command.
Let’s look at how to do this below:
“/nc csm” lists all the available command-sets which you can install from our registry
Let’s install the “corona_stats” command-set to see the stats of the country infected with COVID-19. The Corona stats command set has 1 command, “corona_stats”. We can run the command with “/nc corona_stats” as shown below
Not only, can you install any of the command-sets, you can also modify the code on our online editor. Let’s assume that your country stats are not shown and you want to add it. You can simply run “/nc command_code corona_stats”, make changes on the online editor, save it and run it. Once your changes look fine, you can submit your patch by creating a PR here
After that is merged, how can anyone get your changes? Simple:
You can also create your own command-set in your github repository and install it with “csm”. I have created a command-set on my repo which I can install and run as shown:
Oops! Looks like there’s an error. My command, image-analyser, takes an image URL as an input and analyses and gives an output. However, we don’t see this happening. That’s because I am making an API call to IBM Watson’s api which requires an API key and I don’t want to put the key in the code. So what do I do? I use Commander’s secret store.
Commander provides a way to create secrets and use those secrets in code. We create the secrets like shown below:
Clicking on the link will open the browser and you can add the secret as shown below
After adding the secrets, click on clipboard copy and paste in slack and press enter. Once we do this, we can run the command
How would we use the secrets in code? Simple, by looking the secret argument passed to the function:
Not only do you get a secure storage for your secrets, but you also get access control. Since I installed Commander, that makes me a default admin. Others in the workspace cannot run the commands without permission as shown below
App admins have the ability to create and install commands and also determine who can run, edit or create commands. You can add other admins as shown below
Along with access control, you can also get logging. You can see app, user and command logs, I’ll just show how you can see app logs, but it's easy to see command and user logs. Just run “/nc command_log <command>” and “/nc user_log @user” respectively.
For developers, it might be useful to add logs and to be able to debug while writing commands and Commander allows you to fetch the logs as well. Let’s say I have added a couple of logs to the “hello” command as shown
I will first run the “hello” command and then fetch the logs by running “/nc activation_log” command to fetch the logs as shown below
One of the other useful features is the ability to run the command outside of Slack. You can create a command in Slack but run the command from anywhere and here’s how you do it.
You can use the api_get command to get the command parameters which you can use in your code to call your command or just use curl
This article demonstrated how easy it is to create a serverless Slack command using Nimbella Commander. I showed you how to install Commander, create and run your first command, work with command-sets and also showed you the built in secret-store, access control, logging and debugging that is packed with it.
I’ll conclude by summarizing the benefits of using Nimbella Commander for building Slack apps.
- You don’t have to download any external tools other than Slack.
- There is no infrastructure for you to manage or operate.
- As a developer, you get to focus on writing just the business logic of your app, with Nimbella Commander doing the rest of the heavy lifting for you.
- There is no complicated Slack setup, and you can use and share the slash commands with everyone in your Slack team.
The future for Commander
Slack is one of the integrations we support for Commander. We are working on creating more integrations for other messaging systems such as MS Teams. We also support running commands from anywhere. You would be able to use curl/wget and invoke your commands from the terminal. You can also integrate the commands as serverless buttons on your website. We are also working on a Commander CLI which you use with “nim”, the official Nimbella’s CLI to develop commands and command-sets from your terminal. The other important use of Commander is the ability to write code once and run it on different platforms. Imagine your company exposes 4 APIs and you want to write an App for Slack, MS Teams. You would have to spend several months in development. With Commander, create a Command-set, write 4 commands which use your APIs and publish them as Command-Sets. The users will be able to install and run your “App” on Slack or Teams or even on their terminal! How cool would that be! If you’re interested to track our progress, follow us on Twitter or join our Slack community to get notified of the updates.
- Nimbella joins DigitalOcean
- No infrastructure, just code. Learn the simplicity of serverless
- How to Migrate from Containers to Nimbella Serverless Architecture
- Kubernetes in simple words: explained by Eric Swildens
- How to optimize Kubernetes costs with Nimbella
- Step by step guide on how to port from AWS to Nimbella
- How to build and improve your serverless APIs
- Simplifying Kubernetes For Developers
- FaaS Wars Season 2 - Step By Step Instructions
- What is Nimbella and what does it offer?
- Results and Feedback of FaaS Wars - May the FaaS Be with You!
- 28 Serverless Gurus and experts One Must Follow in 2021
- The Faas Wars Alert!
- CI/CD pipeline with GitHub Actions
- How to deploy Node.js functions on Nimbella
- Kick-Start Your Serverless Journey
- AWS re:Invent Serverless Highlights
- Opportunities in the Wake of the AWS Juggernaut
- FaaS Wars: Serverless & Virtual Robot Competition
- #DeveloperIPL Online Hackathon Results & Feedback on Nimbella's Integration for Postman
- How to connect to the 3rd party database such as MySQL at Nimbella (example in Java)
- What can you do with the Nimbella Workbench?
- Deploy your Shopify Storefront to Nimbella
- Not All Serverless Platforms Are Created Equal
- Nimbella + Netlify: Uplevel Your Development Speed
- How we learned to Jamstack, Our Caputron story | Nimbella.com®
- Commander for Microsoft Teams - Your Custom Bot that runs on your Command!
- How to Build a Stateful Cloud App on Nimbella vs. AWS
- Starter Kit and Resources to Build a Serverless Cloud Application
- How to Build Serverless Slack Apps and Commands
- How to Set up your Serverless Environment and Get Started in Less than 2 Minutes!
- How to Quickly Deploy Stateful Serverless Apps with Nimbella?
- What is Serverless Computing? 3 reasons to start now
- How to Build a Serverless Slack App in Minutes.
- How to Manage your Netlify Website from Slack?
- How to Build a Serverless Slack Command in minutes
- How to Build a Stateful Serverless Cloud Web Application?
- How to Create an Optical Character Recognition (OCR) Application?
- Development at the Speed of Innovation – Nimbella, the Serverless Cloud
- Software Security Features on Enterprise Serverless Slack Apps Enabled by Nimbella Commander
- Coronathon India’s first demo day has 18 projects to help fight COVID-19
- See the time in different cities on Slack with Nimbella Commander
- Greet your friends in their native language in Slack with Nimbella Commander
- How to Fetch your Digital Ocean Billing Info on Slack?
- How to Stay Updated with Coronavirus Statistics on Slack?
- How to Fetch your AWS Billing Info on Slack?
- Get your Datadog billing info in Slack with Nimbella Commander
- Serverless Slack Apps and Slash Commands
- How to use Slack Effectively with Nimbella Commander?
- How to Create a multi-user Chatroom Hosted on Serverless Cloud?
- Using Docker actions, running Golang, and other fun things with OpenWhisk
- The duality between serverless functions and APIs
- Serverless HTTP handlers with OpenWhisk
- Serverless functions in your favorite language with OpenWhisk
- Run Swiftly: precompiled Swift actions
- Performance debugging for serverless functions using the Cloud Shell
- Locally debugging OpenWhisk actions
- Composing functions into applications
- A Serverless Composition of Functions
- The Serverless Contract
- The dawn of the Cloud Computer
- Security and Serverless Functions