When you are running a sales based business it becomes a bit of an obsession to track every transaction and to monitor various numbers. Most people may do this with more than one method depending on the tools they use to power their business.
To set a baseline of what we’ll be doing in this post let me describe the two tools we will be working with today.
- Easy Digital Downloads – This is the software we use to power our ecommerce for all our products. It comes with plenty of reporting built in. For instance we access sales reports from our own WordPress dashboard, we get Pushover notifications every time a sales occurs, and we use the EDD iPhone app to be able to look at the sales numbers of all of our products. We probably didn’t need another channel for getting these numbers but like I said, it becomes a bit obsessive.
- Slack – This is a team communication tool. It allows you to add channels for various parts of your business or team to keep all your discussion online and searchable. We’ve been using this tool for about 6 months now and have really come to love the flexibility and power it provides. It comes with plenty of integrations so you can connect Slack with all your other tools. This has become invaluable to us as a business for both communication internally but also for monitoring chatter about us and our products externally. I’ll share more about how we use Slack in another post.
If you also are using both of these tools what I’m about to share will be perfect for you. If you are using only one of these tools perhaps you might consider adding the other to those you already use. Either way, let’s have some fun.
What are Slash Commands?
Slack explains Slash commands best like this:
Slash Commands allow you to listen for custom triggers in chat messages across all Slack channels. When a Slash Command is triggered, relevant data will be sent to an external URL in real-time.
Once the external URL receives the request you can write something that returns some pertinent information back to Slack and this will be displayed privately to you in the channel that you entered the command.
The command we are going to create is /sales. When this is entered, whether with some extra text or alone, we are going to return some specific sales data.
Setting up your Slash Command
Before we get into the code that you will write on your site that has EDD running on it let’s set up the Slash Command within Slack.
1. Log into Slack and select “Configure Integrations”
2. Scroll to the bottom of the page and select “Add” next to the “Slash Commands” item
3. Create your Slash Command
Here you will enter the initial command that will trigger the call to your website. We are using /sales in this example but if you have multiple sites and want to grab that data you may want to make that command more unique. We use /nfsales to get Ninja Forms sales and /ndsales to get Ninja Demo sales.
This is the URL Slack will make it’s request to once you enter the command. We are just using our man sites URL but we add a slack_slash query as well to make sure that this isn’t being checked every time the site is visited. I would recommend changing “your_custom_string” to a fairly long random unique key. This will prevent anyone from being able to guess it and exploit your site or retrieve data they should have access to. Re,ever what you enter here because we’re going to need it when we get to our actual code.
This is the default option and can be left as is.
This is auto generated and you will not to make note of it because we will be using it in our code.
Here you can describe your new command and add some additional usage hint text. For instance our command will allow additional key words like day. month, year, lifetime, and average to get more specific data.
Once you are done with that click “Save Integration” and you are ready to write your code.
Creating Your Response to Slack
Now it’s time to write some code on our site to process this request from Slack. I suggest placing this code into a custom plugin.
You will want to add your own sites URL and any tokens you’ve created but once you upload this new plugin with the above code you should now be able to go into any of your Slack channels and type the following commands:
- /sales day
- /sales month
- /sales year
- /sales lifetime
- /sales average
The server will respond with the responses from your code right in your Slack channel and you’ll be able to get updates whenever the mood strikes you.
I hope you found this helpful and if you have any thoughts on what would be even cooler let me know so I can add it. 🙂