How to set Slack alerts when your business data changes

Slack alerts are an effective way to stay on top of important business events. This blog explains how to configure Slack notifications in various ways.

Posted by Ameena on 2023-04-18
How to set Slack alerts when your business data changes

As a business owner, you've got a lot on your plate, from juggling a myriad of responsibilities to making tough calls left and right. But let's be real: What's the point of making decisions based on events that happened a week ago? It's like trying to drive forward while looking in the rearview mirror. If you're not keeping up with the latest developments, you might as well be driving blindfolded. And we all know that's not a good idea. That's why it's essential to stay in the loop in real-time. Of course, you can't be glued to your screen all day. So Slack notifications are here to save the day (and your sanity).

The Value of Timely Business Updates through Slack Alerts

  1. Data on finger tips: With Slack alerts, accessing crucial business data has never been easier. As a business owner, it's easy to access crucial metrics like the daily install count by simply reviewing the alerts that have been established. By adopting this approach, you can optimise your time and efforts while staying informed about critical data that can influence your business decisions.
  2. Recognise anomalies: Suppose you typically receive a certain number of sign-ups per day, and suddenly that number drops by half. This drop in sign-ups is a clear indication that there is a software flaw in your product, and by identifying it through timely Slack notifications, you can quickly take corrective measures before the situation worsens.
  3. Power your decision-making with timely insights: Alerts can provide crucial insights into customer behaviour and help you make better decisions faster. For instance, if you notice that a specific feature in your product is being used by the majority of your paying customers, it might be worthwhile to consider making that feature available to your free users as well. Without these timely alerts, you may miss out on valuable insights and delay decision-making, which can hinder your business's growth.
  4. Ensures team motivation: If you provide your team members with access to Slack alerts, they'll be aware of the progress being made, which can inspire them to work with even more enthusiasm towards achieving the next milestone.
  5. Track progress in real-time: When you track feature usage through alerts, you can identify progress and successes that might otherwise go unnoticed. Celebrating these milestones with your team can boost morale and help you determine where to focus your efforts. Whether you need to make further improvements to a successful feature or shift your focus to a different area of the product, measuring progress through timely updates can help you make informed decisions.

But wait, there's more! I've already given you plenty of reasons why setting up Slack notifications is a smart move for any business owner. In the following sections, I'll show you two different ways to set up these alerts. The first option involves coding, while the second option is much simpler and more convenient, using Draxlr.


How to setup a Slack alert via code?

Suppose you want to keep track of the daily sign-ups for your app and only receive Slack notifications when the total number of users changes.

Let's see some examples of how to achieve these in different frameworks. You will need a Slack Webhook URL; you can follow this guide to generate one.

Ruby on Rails

In Ruby, you can accomplish this by using a gem called slack-notifier. This gem provides an easy-to-use wrapper for posting messages to Slack channels.

Steps to follow

  1. Add slack-notifier to your Gemfile and run bundle install.
  2. Add a callback to the user model when the user is created or destroyed.
# Gemfile
gem "slack-notifier"

# app/models/user.rb
...
after_create :send_slack_notification
after_destroy :send_slack_notification

def send_slack_notification
  Slack::Notifier.new(slack_webhook_url).ping("User count changed to #{User.count}")
end
...

ExpressJS with Mongoose (NodeJS)

You can accomplish this by using a package called slack-notify.

Steps to follow

  1. Add slack-notify to your package.json and run npm install.
  2. Add a method to the user model and call it when the user is created or destroyed.
# User.js
...
import SlackNotify from 'slack-notify';
const SLACK_WEBHOOK_URL = '<PASTE YOUR WEBHOOK URL HERE>';
const slack = SlackNotify(SLACK_WEBHOOK_URL);

const userSchema = new mongoose.Schema({
  // fields
})

// user.sendUserCountNotification()
userSchema.methods.sendUserCountNotification = async function () {
  const userCount = await User.countDocuments()
  await slack.send(`User count changed to ${userCount}`)
}
...

Django

You can accomplish this by using a package called slack-sdk.

Steps to follow

  1. Add slack_sdk to your project requirements using pip install slack_sdk.
  2. Add a signal listener for user object creation or deletion.
# <app_name>/signals.py
from django.dispatch import receiver
from django.db.models.signals import post_save, post_delete

from slack_sdk.web.client import WebClient

from userman.models import User

client = WebClient("<your_access_token>")


@receiver(post_save, sender=User, dispatch_uid="handle_user_create_signal")
def handle_user_create(sender, instance, **kwargs):
    notify_user_count_slack()

@receiver(post_delete, sender=User, dispatch_uid="handle_user_delete_signal")
def handle_user_delete(sender, instance, **kwargs):
    notify_user_count_slack()

def notify_user_count_slack():
    user_count = User.objects.count()
    message = f"User count changed to {user_count}"
    client.chat_postMessage(channel="<channel_name>", text=message)

How to setup Slack alerts via Draxlr

  1. Connect your Draxlr account with the Slack workspace by going to Settings > Organization Settings.
  2. If you're looking to set up a Slack alert in a private channel, don't forget to give a warm welcome to your newest team member - Draxlr! Simply invite Draxlr to the channel by mentioning @Draxlr, and let it handle the rest.
  3. You can now generate the same query as the usecase mentioned above using Draxlr. Draxlr generate query
  4. Next, head over to the "Integrations" option in the navigation bar. Draxlr create alert
  5. Enter the channel name where you want the notifications to appear. Draxlr test alert
  6. Once it's done, you can now simply select the query that you want to receive notifications for and specify the frequency of alerts that you desire. Draxlr slack alert details
  7. You will receive Slack notifications with a format similar to this. Draxlr slack alert notifications

With just a few clicks, you can now receive important updates in real-time through Slack alerts. It's the perfect solution for business owners who need to stay informed about critical events without constantly checking. So why wait? Sign up for Draxlr today and experience the convenience of hassle-free Slack alerts for yourself!

Let’s get you started

This website uses cookies to ensure you get the best experience.