Slack

The PM’S Guide to Sending Real-Time Transactional Notifications Using Slack Webhooks (With JSONNET)

April 27, 2023
TABLE OF CONTENTS

Slack Webhooks are a powerful tool for startups looking to create automated messaging within Slack. By utilizing a webhook URL to receive HTTP requests, developers can trigger specific actions within Slack, such as sending messages or updating channel topics. You can even send incoming JSON payloads (notification content) directly to pre-made Slack messaging templates without coding from scratch. 

For business use cases, Slack transactional messages keep users engaged and reduce churn. These Slack transactional notifications are sent in response to a specific action or event, such as an approval request, incident alert, or task creation, or ticket raised on JIRA. 

This article will check the step-by-step process of sending transactional notifications using Slack incoming webhooks. 

Using Slack Webhooks for Transactional Notifications

The below table categorizes the different types of transactional notifications you can send using Slack Webhooks via SuprSend.

Notification Type Description Example Use Case
Channel Notification Send a message to a specific channel Notify a customer support team when a user submits a ticket
User Notification Send a message to an individual user Send an automated message to a user when they reach a milestone in your application
Channel Topic Update Update a channel topic with relevant information Update the channel topic with project due dates


Let’s check various B2B use-cases for which businesses send transactional notifications on Slack. With SuprSend, you can get specific Slack messaging templates designed for each use case.

User/Account Management

  • Welcome message to new business clients
  • Confirmation of business account creation
  • Notification of successful integration with the client's system
  • Notification of account termination/cancellation
  • Notification of account approval for a business partner

Payment/Transaction Management

  • Payment received confirmation
  • Payment failure notification
  • Transaction dispute notification
  • Notification of successful transaction between businesses
  • Request for payment notification

Order/Shipping Management

  • Order confirmation for bulk purchases
  • Notification of successful shipment
  • Notification of delayed shipment
  • Order cancellation notification for bulk purchases
  • Notification of order customization approval

Support/Ticket Management

  • New support ticket notification for B2B clients
  • Ticket escalation notification for high-priority issues
  • Notification of successful ticket resolution
  • Notification of ticket update for B2B clients
  • Notification of ticket closure

Task Management

  • Notification of assigned tasks to B2B clients
  • Notification of task completion for B2B clients
  • Task reminder notification for B2B clients
  • Notification of task update for B2B clients
  • Task due date notification for B2B clients

Event Management

  • Event reminder notification for B2B clients
  • Notification of event cancellation due to unforeseen circumstances
  • Notification of event rescheduling for B2B clients
  • Event registration confirmation for business partners
  • Notification of successful event attendance by business partners

System/Technical Management

  • System maintenance notification for B2B clients
  • System outage notification for B2B clients
  • Notification of critical errors in system/technical operations
  • Server utilization notification for B2B clients
  • Notification of successful system/technical integration with business clients.

Setting Slack Webhooks for Transactional Notifications

To set up a Slack webhook, you'll first need to create an app in the Slack App Directory and configure it with the appropriate permissions and settings. Once your app is set up, you can generate a unique webhook URL that you can use to send messages to specific channels or users. You can then use the Slack API to send messages to your webhook URL, including message text, attachments, and other metadata.

Check below the step-by-step process to set up your Slack webhook for your app.

Step 1: Creating a Slack Webhook on App

The first step in setting up a Slack Webhook for transactional notifications is creating a webhook in your Slack workspace. To do this, login to your Slack account and follow these steps:

Go to the Slack API website and click "Start Building" to create a new app. Select ‘From Scratch’.


Click on "Incoming Webhooks" and activate the feature by setting the toggle switch to "On."


Scroll down and click "Add New Webhook to Workspace."


Choose the channel where you want to send notifications and click "Authorize." Make sure to add a ‘Sandbox’ channel for testing purposes, before integrating it into the main channel.

Step 2: Configuring Your Webhook

Once you have created your Slack Webhook, you must configure it to send transactional notifications. To do this, you must determine the appropriate type of webhook to use - incoming or outgoing. Check the below table for a comparison between incoming and outgoing webhooks.

Feature Incoming Webhooks Outgoing Webhooks
Purpose Receive data from external sources and post it to Slack Send data from Slack to external sources
Trigger External application or service sends data to webhook URL Slack event or user interaction triggers webhook
Configuration Configured by external application or service Configured by Slack workspace administrator or developer
Message Formatting Limited formatting options for incoming data Full range of formatting options for outgoing data
Authentication No authentication required for incoming data Outgoing data requires authentication via Slack API token
Scope Only available to workspace administrators and developers Available to all users in a Slack channel or direct message
Examples Receive notifications from external apps (e.g., JIRA, Trello, Github) and post them in a Slack channel Automatically update a third-party app when a user types a command in Slack (e.g., /weather, /translate, /poll)


For transactional notifications, you should use an Incoming Webhook, as you will be sending messages from your external application to Slack.

Step 3: Testing Your Webhook

Once you have created and configured your Slack Webhook, you must test it to ensure it works correctly. There are a variety of tools and libraries that you can use to test your webhook endpoint. Some need syntax, while others have UI for direct webhook creation. 

To test your webhook endpoint using cURL (Slack recommended), for example, you can run the following command in your terminal:

Tool Example Syntax
RequestBin Not applicable
ngrok ngrok http 3000 (where 3000 is the port number of your local server)
Zapier Not applicable
Postman Not applicable
cURL curl -X POST -H "Content-type: application/json" -d '{"text":"Hello World"}' https://hooks.slack.com/services/XXX/YYY/ZZZ (where the last part is your webhook URL)
Python's requests library import requests payload = {'text': 'Hello World'} requests.post('https://hooks.slack.com/services/XXX/YYY/ZZZZ', json=payload) (where the last part is your webhook URL)
Slack API Testing Tools Not applicable


To test your webhook endpoint using cURL (Slack recommended), for example, you can run the following command in your terminal:

Copy code:

curl -X POST -H ‘Content -type: application/json’ . --data . ‘{“text”:”Hello, world!”}’ https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXX


Replace the webhook URL with your own Incoming Webhook URL and the message text with your own test message.

Step 4: Securing Your Webhook

Security is an important consideration when setting up Slack Webhooks for transactional notifications. There are a few key best practices that you should follow to ensure that your webhook is secure:

  • Use HTTPS: Always use HTTPS when communicating with your webhook endpoint to ensure that data is encrypted in transit.
  • Use authentication: Use an authentication method, such as a shared secret or API key, to ensure that only authorized parties can send messages to your webhook.
  • Validate input: Validate all incoming messages to ensure they are formatted correctly and do not contain malicious content. This helps to prevent attacks such as cross-site scripting (XSS) and SQL injection.
  • Monitor activity: Monitor your webhook activity for signs of suspicious activity, such as a sudden spike in traffic or unusual message content.

By following these best practices, you can help ensure the security and reliability of your Slack Webhook for transactional notifications.

Creating Multiple Triggers For Transactional Notifications

Creating triggers for transactional notifications is critical in automating message sending through Slack Webhooks. To create triggers, you must follow these steps:

  1. Identify all important events or actions: Identify the key events or actions you want to notify users about. These could include events like order confirmations, shipping notifications, or account alerts.
  2. Configure Slack webhook for each trigger: Configure your Slack webhook to listen for these triggers and send messages accordingly. This can be done using a webhook integration platform like Zapier or Integromat. You can write a custom script or application to listen for events in your database or API.

Creating templates on Slack Block Kit & JSONNET

After configuring your Slack webhook, create and customize trigger configurations for various use cases. You can include variables in your message using JSONNET and Slack Block Kit, to make notifications easier and more interactive. 

For example, the below example showcases a Slack message template for "approval" that utilizes JSONNET to pass on variables, making it simple to integrate at scale. 

Refer to the code below for this example message.

Example Trigger Configurations for Transactional Notifications:

In this example, we send a message to a Slack channel for an ‘approval’ request. The JSONNET payload contains the message text and action buttons, which include details about the approval request, such as data approver, data purchaser, and data software. 

The webhook URL is where the message will be sent, and we are using the requests library to make the HTTP POST request to the webhook URL.

Example for sending multiple Slack notifications with webhooks for multiple triggers:

JSONNET code for sending Slack notifications for new user registrations and orders (multiple triggers) using webhooks.

This code defines a list of messageBlocks that represent the Slack message blocks for each trigger. It also defines a list of triggers, where each trigger is associated with an event and a data object that represents the data for that event. 

The code then loops through the triggers and uses the message and webhook external variables to send the appropriate message block to the appropriate webhook URL for each trigger. The payload object contains the message block and the channel where the message will be sent, and the http.post function sends the message to the webhook URL using an HTTP POST request.

In this example, there are two triggers defined:

new_user_registration and new_order. The message_new_user_registration and webhook_new_user_registration external variables define the message block and the webhook URL for the new_user_registration trigger, and the message_new_order and webhook_new_order external variables define the message block and the webhook URL for the new_order trigger.

Using SuprSend to create Slack message templates with variables

With SuprSend, you can visually design your message templates and add variables using JSONNET. The platform provides a preview feature, allowing you to update and customize the template. Once you're satisfied with the design, you can trigger Slack notifications by passing events with variables in JSON.

Handling Multiple Webhooks

If you have multiple applications or systems that need to send notifications to Slack, you can create multiple Webhooks and manage them separately.

When dealing with multiple Slack Webhooks, a common challenge is to ensure that notifications are delivered reliably and without duplication. One approach to solving this challenge is to use a message broker like Apache Kafka to manage the delivery of notifications.

Example Apache Kafka code to manage multiple Slack webhook functionality

Here's how you can use Apache Kafka to manage notification delivery:

1. Create a topic in Kafka for each type of notification that you want to send. For example, you could create a topic called "order-notifications" for notifications related to new orders.

2. When an event occurs that triggers a notification, produce a message to the corresponding topic in Kafka. The message should contain all the necessary information to generate the notification, such as the order number, customer name, and notification message.

Example Kafka Producer Code:

3. Set up a Kafka consumer that listens for messages on each topic and sends them to the appropriate Slack Webhook. The consumer should handle the routing and deduplication of messages to ensure that notifications are delivered reliably and without duplication.

Example Kafka Consumer Code:

Using a message broker like Apache Kafka can help ensure that notifications are delivered reliably across multiple Slack Webhooks, even in the event of network or server issues. The message broker can handle the routing and deduplication of messages, reducing the risk of duplicate or missed notifications.

You can even include an idempotency key to ensure no duplicate notifications are being sent. SuprSend helps you with this feature. 

To implement idempotency, you can use a unique identifier for each notification and store it in a database or cache. Before sending a notification, you can check if the identifier already exists, and if so, skip the notification to avoid duplicate messages. If the identifier does not exist, you can proceed with sending the notification and store the identifier for future checks.

Example idempotency code snippet in Python:

In this example, the send_slack_notification() function generates a unique identifier for each notification using the uuid module. It then checks if the identifier already exists in the database or cache using the check_notification_id() function. 

If the identifier exists, the function returns without sending the notification. If the identifier does not exist, the function constructs the Slack Webhook payload, sends the notification using the requests library, and stores the identifier using the store_notification_id() function. If there is an error sending the notification, the function calls the handle_notification_error() function to handle the error or retry logic.

Handle errors and retries: 

Handling errors and retries is crucial to ensure that notifications are delivered reliably. You can implement error-handling mechanisms such as retrying failed messages or logging errors for later analysis. This can be done using Slack's retry-after header or by implementing custom retry logic in your script or application.

SuprSend provides a robust fallback mechanism with both channel and vendor fallback options, along with retries.

Moreover, you also get real-time delivery logs to audit and analyze the successful or failed delivery processes.

In addition to identifying triggers for transactional notifications, it's also important to consider the frequency and timing of these notifications. While it's important to keep users informed and engaged, it's equally important not to overwhelm them with too many notifications or to send them at inconvenient times.

To address this, you might consider setting up rules or thresholds for when notifications should be sent. For example, you might only send a shipping notification when an item is actually shipped, rather than when it's just been packed and labeled. Or you might send account alerts only when a payment fails multiple times, rather than every time a payment fails.

With SuprSend, you can use the batching and digest features to create a positive user experience.

Additional Factors Affecting Transactional Notifications with Slack Webhooks

Slack Webhooks are a powerful tool for sending transactional notifications, but as your usage grows, you may encounter more complex scenarios that require advanced configuration. 

Rate Limiting

Rate limiting is a mechanism used to prevent the overloading of API endpoints by limiting the number of requests that can be sent within a given time period. Slack has rate limits for their Webhook APIs to ensure they remain stable and performant. Knowing these rate limits is essential to design your notification infrastructure.

Feature/API Limit Note
Web API Tier 1 1+ per minute Access tier 1 methods infrequently. A small amount of burst behavior is tolerated.
Web API Tier 2 20+ per minute Most methods allow at least 20 requests per minute while allowing for occasional bursts of more requests.
Web API Tier 3 50+ per minute Tier 3 methods allow a larger number of requests and are typically attached to methods with paginating collections of conversations or users. Sporadic bursts are welcome.
Web API Tier 4 100+ per minute Enjoy a large request quota for Tier 4 methods, including generous burst behavior.
Web API Special Tier Varies Rate limiting conditions are unique for methods with this tier. For example, chat.postMessage generally allows posting one message per second per channel, while also maintaining a workspace-wide limit.
Posting messages 1 per second Short bursts >1 allowed. If you attempt bursts, there is no guarantee that messages will be stored or displayed to users. If the burst exceeds available limits, users will see an error message indicating that some messages from your app are not being displayed.
Incoming webhooks 1 per second Short bursts >1 allowed.
Events API events 30,000 deliveries per hour per workspace Larger bursts are sometimes allowed.


Source: Slack Rate Limits

Backoff Strategies

Backoff strategies are a way to handle errors and retries more intelligently. Instead of simply retrying immediately after a failed attempt, backoff strategies introduce a delay between retries to reduce the load on the API and increase the chances of success. With SuprSend, you can try these backoff mechanisms.

Backoff Strategy Description
Exponential Backoff This is the most commonly used strategy, where the delay between retries increases exponentially with each retry. For example, the delay between the first and second retry might be 1 second, between the second and third retry might be 2 seconds, and so on.
Linear Backoff In linear backoff, the delay between retries increases by a fixed amount with each retry. For example, the delay between retries might be 5 seconds, 10 seconds, 15 seconds, and so on.
Random Backoff Random backoff introduces an element of randomness into the delay between retries. This can help prevent retries from becoming synchronized, which can overload the system. For example, the delay between retries might be randomly generated between 1 and 10 seconds.
Adaptive Backoff Adaptive backoff adjusts the delay between retries based on the response time of the previous request. If the previous request was successful, the delay between retries is decreased, but if the previous request failed, the delay is increased. This can help optimize the retry process based on the current network conditions.

Using Slack's Event API

Slack's Event API is a more advanced way to handle notifications, especially if you have complex use cases or multi-step notifications. The Event API allows you to listen for events within Slack, such as new messages, reactions, or file uploads.


With the Event API, you can build complex notification workflows triggered by specific events, such as mentions of certain keywords (in the above example, ‘Good morning’) or file uploads to specific channels. With the Event API, you can also create multi-step notifications, prompting recipients to take a series of actions before the notification is considered complete.

To use Slack's Event API, you'll need to create an Event Subscription and configure a Request URL to receive event payloads. Additionally, you'll need to create an Event Handler to process incoming events and trigger appropriate notifications. We’ll talk more about this section in another article. 

Best Practices for Sending Transactional Notifications on Slack

Tip 1: Keep Notifications Concise and Actionable

Provide only the most critical information that is relevant to the recipient. Use dynamic content if needed. For example, a notification about a new order can include the order number, customer name, and a link to view the order details.

Tip 2: Handle Errors and Retries

Handle errors and retries to ensure reliable delivery. Slack has built-in retry mechanisms, but it's important to have a backup plan in case of persistent failures. Use a queuing system to store notifications that cannot be delivered immediately and retry sending them at specified intervals.

Tip 3: Monitor Transactional Notifications

Monitor transactional notifications to ensure they are delivered reliably and effectively. Use Slack's API to track notification activity, such as the number of notifications sent and response times. 

Third-party tools like SuprSend and Datadog can provide real-time visibility and help you troubleshoot issues quickly. Collect feedback from team members to improve the effectiveness of your notifications.

Written by:
ABOUT THE AUTHOR

What’s a Rich Text element?

The rich text element allows you to create and format headings, paragraphs, blockquotes, images, and video all in one place instead of having to add and format them individually. Just double-click and easily create content.

Static and dynamic content editing

A rich text element can be used with static or dynamic content. For static content, just drop it into any page and begin editing. For dynamic content, add a rich text field to any collection and then connect a rich text element to that field in the settings panel. Voila!

How to customize formatting for each rich text

Headings, paragraphs, blockquotes, figures, images, and figure captions can all be styled after a class is added to the rich text element using the "When inside of" nested selector system.

Implement a powerful stack for your notifications

By clicking “Accept All Cookies”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. View our Privacy Policy for more information.