Set up Ecommerce Order Notifications on Slack in 5 minutes with Medusa
Tags: javascript, tutorial, opensource, webdev
Published: 2022-03-22 12:57:41

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](https://slack.com), which many companies already use for internal communication.

If you’re not familiar with [Medusa](https://www.medusajs.com), it’s a headless [open source ecommerce](https://dev.to/medusajs/open-source-ecommerce-how-medusa-compares-to-shopify-3ef) 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](https://slack.com).

### Medusa Server

This tutorial assumes you already have a Medusa server installed. If you don’t, please follow along with [the quickstart guide](https://docs.medusajs.com/quickstart/quick-start).

### Redis

Medusa uses [Redis](https://redis.io) 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](https://docs.medusajs.com/tutorial/set-up-your-development-environment#redis).

## 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](https://api.slack.com) and click Create app. This will take you to a new page with a pop-up. In the pop-up, choose From scratch.


![Create app](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/92ml54qc1fz3n9zde2sf.png)

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.

![Incoming Webhooks](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v1u3z360aqrf36303ldw.png)

### Add New Webhook

After activating Incoming Webhooks, on the same page scroll down and click on the Add New Webhook to Workspace button.

![Add New Webhook](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m3de1gcd8etvvlxjy4re.png)

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.

![Choose channel or DM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kotp1wl8ljdejtax8qft.png)

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](https://github.com/medusajs/medusa/tree/master/packages/medusa-plugin-slack-notification) into your Medusa server.

Open the terminal in the Medusa server’s directory and run the following command:

```bash
npm install medusa-plugin-slack-notification
```

After that, open `medusa-config.js` and add the new plugin with its configurations in the `plugins` array:

```jsx
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](https://docs.medusajs.com/starters/nextjs-medusa-starter).

![Order Created](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o7kffu3myljrkedo4orn.png)

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.

![Slack Notification](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/679ajvgd5p3y5xc3lni6.png)

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](https://github.com/medusajs/admin) to learn how you can install it.

![Admin Dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g0ft4l9exre4xz28p1h4.png)

## 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](https://github.com/medusajs/medusa/tree/master/packages) 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](https://discord.gg/F87eGuwkTp).