This directory holds the code for the Slack Integration Tutorial.
You can either:
- install and use it as a Medusa application;
- or copy its source files into an existing Medusa application.
- Node.js v20+
- Git CLI
- PostgreSQL
- Slack account with an application.
- Clone the repository and change to the
slack-integrationdirectory:
git clone https://github.com/medusajs/examples.git
cd examples/slack-integration2. 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/appWhere:
SLACK_WEBHOOK_URLis the webhook URL to send notifications to.SLACK_ADMIN_URLis the URL prefix of the Medusa Admin. By default, it'shttp://localhost:9000/appin development.
Learn more about retrieving these variables in the tutorial
5. Install dependencies:
yarn # or npm install6. Setup and seed the database:
npx medusa db:setup
yarn seed # or npm run seed7. Start the Medusa application:
yarn dev # or npm run devFinally, 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.
If you have an existing Medusa application, copy the following directories and files into your project:
src/modules/slacksrc/subscriberssrc/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/appWhere:
SLACK_WEBHOOK_URLis the webhook URL to send notifications to.SLACK_ADMIN_URLis the URL prefix of the Medusa Admin. By default, it'shttp://localhost:9000/appin development.
Learn more about retrieving these variables in the tutorial
After that, install the axios package:
yarn add axios # or npm install axiosFinally, 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.