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.
Why use Serverless Slack Apps?
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”.
How to Build a Currency Converter slash command?
Without further ado, let’s get started. The slash command we will be writing today is a simple currency converter.
/nc convert <from> <to>
The above command will convert 1 unit of from the from parameter to the to parameter. For example, running
/nc convert usd eur will convert 1 USD to Euro.
Before we could build our own custom command in Commander, we need to install it. In 2 simple steps, we will install Commander and create a basic slash command that users can run in Slack.
- First, 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.
Try it and type
/nc command_create demo to create a demo command 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.
- Now let’s create a currency converter command. The command should take 2 mandatory parameters, “from” and “to”. from is the currency we want to convert and to is the currency we want to convert it to. We will again use command_create for this.
/nc command_create convert <from> <to> into Slack. Once you run the command, click the “edit the code” button to pull up the code for your newly created command.
- Now once you create a command, let's write the logic for the currency converter. We will use the exchange-rates-api npm package to convert the currency. You can find the source of the command here. Copy the code from the link and paste it over all the code found in the page that pulls up when you click “edit the code”.
- Once this is done, press “Save”, go back to your Slack prompt and run the command
/nc convert usd eur. As shown below, the command converts 1 USD to Euro.
Why use Nimbella Slack Commander?
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, and how to create a more interesting example.
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.
For our next blog, we will cover more advanced Nimbella Commander features, which include the following:
- Command-Sets: a way for creating and sharing Slack commands with others.
- Learn about Command-Sets that we have open-sourced and how to install them in your Slack with a single command.
- How to use Commander’s built-in access-control, logging, and monitoring so that you can control who can create, edit, or run your commands, and audit who’s using them.
Written by Nikhil Prakash (Twitter)
- How to Manage your Netlify Website from Slack?
- How to Build a Serverless Slack Command in minutes
- A Serverless Cloud for Stateful Applications
- A Template for Creating a Serverless OCR App
- 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
- Install Commander on your Mattermost Instance
- Get your DigitalOcean Billing Info in Slack with Nimbella Commander
- Get live Coronavirus stats in Slack with Nimbella Commander
- Create BlueJeans meetings on Mattermost using Commander
- Get your AWS billing info in Slack with Nimbella Commander
- Get your Datadog billing info in Slack with Nimbella Commander
- Serverless Slack Apps and Slash Commands
- How to use Slack Effectively with Nimbella Commander?
- A Template to Build a Serverless Chat App
- 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