Skip to content

Latest commit

 

History

History
124 lines (87 loc) · 3.46 KB

File metadata and controls

124 lines (87 loc) · 3.46 KB

Medusa v2 Example: Slack Integration

This directory holds the code for the Slack Integration Tutorial.

You can either:

Prerequisites

Installation

  1. Clone the repository and change to the slack-integration directory:
git clone https://github.com/medusajs/examples.git
cd examples/slack-integration

2. Rename the .env.template file to .env.

3. If necessary, change the PostgreSQL username, password, and host in the DATABASE_URL environment variable.

4. Set the Slack environment variables:

SLACK_WEBHOOK_URL=
SLACK_ADMIN_URL=http://localhost:9000/app

Where:

  • SLACK_WEBHOOK_URL is the webhook URL to send notifications to.
  • SLACK_ADMIN_URL is the URL prefix of the Medusa Admin. By default, it's http://localhost:9000/app in development.

Learn more about retrieving these variables in the tutorial

5. Install dependencies:

yarn # or npm install

6. Setup and seed the database:

npx medusa db:setup
yarn seed # or npm run seed

7. Start the Medusa application:

yarn dev # or npm run dev

Finally, place an order and a notification will be sent to the configured Slack channel in the Slack app. You can use the Next.js Starter Storefront to place an order.

Copy into Existing Medusa Application

If you have an existing Medusa application, copy the following directories and files into your project:

  • src/modules/slack
  • src/subscribers
  • src/workflows

Then, add the Slack Module to medusa-config.ts:

module.exports = defineConfig({
  // ...
  modules: [
    {
      resolve: "@medusajs/medusa/notification",
      options: {
        providers: [
          {
            resolve: "./src/modules/slack",
            id: "slack",
            options: {
              channels: ["slack"],
              webhook_url: process.env.SLACK_WEBHOOK_URL,
              admin_url: process.env.SLACK_ADMIN_URL,
            },
          },
        ],
      },
    },
  ],
})

Next, add the following environment variables:

SLACK_WEBHOOK_URL=
SLACK_ADMIN_URL=http://localhost:9000/app

Where:

  • SLACK_WEBHOOK_URL is the webhook URL to send notifications to.
  • SLACK_ADMIN_URL is the URL prefix of the Medusa Admin. By default, it's http://localhost:9000/app in development.

Learn more about retrieving these variables in the tutorial

After that, install the axios package:

yarn add axios # or npm install axios

Finally, place an order and a notification will be sent to the configured Slack channel in the Slack app. You can use the Next.js Starter Storefront to place an order.

More Resources