When you run an ecommerce store, it’s important to keep track of all orders placed to fulfill your customers quickly. There are many ways to receive notifications for new orders, and one of them is using automated messages on Slack, which many companies already use for internal communication.
If you’re not familiar with Medusa, it’s a headless open source ecommerce platform having an architecture built with extendability and customization in mind. This means that you can integrate almost anything into your Medusa server.
Slack is one of the services you can integrate into Medusa to receive notifications whenever a customer places a new order. It is already vividly used among existing Medusa users
In this tutorial, you’ll learn how to add the Slack plugin to your Medusa server to start receiving order notifications.
Prerequisites
Slack Account
To follow along with this tutorial, you need to have a Slack account with a connected workspace. If you don’t have one, you can create a free account on Slack.
Medusa Server
This tutorial assumes you already have a Medusa server installed. If you don’t, please follow along with the quickstart guide.
Redis
Medusa uses Redis to dispatch events when a certain action occurs, such as when an order is placed. This will allow event handlers to perform actions when the event occurs, which in this case is sending a notification to your Slack workspace.
After you install and run Redis, make sure you add your Redis URL to your Medusa server.
Create Slack App
The first step is to create a Slack app. This app will be connected to your workspace and will have Incoming Webhooks activated to receive notifications from the Medusa server using a Webhook URL.
Go to Slack API and click Create app. This will take you to a new page with a pop-up. In the pop-up, choose From scratch.
You’ll then need to enter some info like the App name and the workspace it will be connected to. Once you’re done, the app will be created.
Activate Incoming Webhooks
To activate Incoming Webhooks, choose Features > Incoming Webhooks from the sidebar. At first, it will be disabled so make sure to enable it by switching the toggle.
Add New Webhook
After activating Incoming Webhooks, on the same page scroll down and click on the Add New Webhook to Workspace button.
After that, choose the channel to send the notifications to. You can also choose a DM to send the notifications to. Once you’re done click Allow.
This will create a new Webhook with a URL which you can see in the table at the end of the Incoming Webhooks page. Copy the URL as you’ll use it in the next section.
Install Slack Plugin
The next step is to install Medusa’s Slack plugin into your Medusa server.
Open the terminal in the Medusa server’s directory and run the following command:
npm install medusa-plugin-slack-notification
After that, open medusa-config.js
and add the new plugin with its configurations in the plugins
array:
const plugins = [
...,
{
resolve: `medusa-plugin-slack-notification`,
options: {
show_discount_code: false,
slack_url: `<WEBHOOK_URL>`,
admin_orders_url: `http://localhost:7001/a/orders`
}
}
];
Make sure to change <WEBHOOK_URL>
with the Webhook URL you copied after creating the Slack app.
The show_discount_code
option enables or disables showing the discount code in the notification sent to Slack. The admin_orders_url
is the prefix of the URL of the order detail pages on your admin panel. If you’re using Medusa’s Admin locally, it should be http://localhost:7001/a/orders
. This will result in a URL like http://localhost:7001/a/orders/order_01FYP7DM7PS43H9VQ1PK59ZR5G
.
That’s all you need to do to integrate Slack into Medusa!
Test it Out
To test it out, you need to create an order on your Medusa server. One way to do that is using a storefront. If you don’t have one, you can follow our quickstart guide to install a Next.js starter.
After creating the order, you’ll receive a notification on Slack in the channel or direct message you chose when you created the app. The notification will include order details like products ordered, order total, customer details, and more.
You can also click on the order number URL in the notification to view the order in the admin dashboard. If you don’t have an admin dashboard installed you can check out Medusa’s Admin repository to learn how you can install it.
Conclusion
As a headless open source ecommerce platform, Medusa provides you with a robust and fast ecommerce store that can also be integrated into many tools and services. This can boost your business’ operation and help you attend to more customers easily.
In this tutorial, you learned how to integrate Medusa and Slack to receive order notifications right in your workspace. Medusa has more plugins that you can also easily integrate to add more functionalities and features to your ecommerce store. There is a wide range of plugins related to marketing, analytics, file storage, and more.
Should you have any issues or questions related to Medusa, then feel free to reach out to the Medusa team via Discord.