Skip to content

Notification

ShipSaaS supports sending notifications when a user successfully completes a purchase, allowing your team to receive real-time order alerts in your preferred workspace tools.

Currently, two notification channels are supported: Discord and Feishu. You can add more notification channels by implementing the NotificationProvider interface.

Enable the notification feature in src/config/website.ts and configure the channel to receive messages:

src/config/website.ts

export const websiteConfig: WebsiteConfig = {
// ...other config
notification: {
enable: true,
provider: 'discord', // or 'feishu'
},
// ...other config
}

Based on your chosen notification channel, configure the corresponding Webhook URL:

  1. Open your Discord server and navigate to the channel where you want to receive notifications.
  2. Click the gear icon to open Channel Settings.
  3. Select Integrations > Webhooks > New Webhook.
  4. Set a name and an avatar for the Webhook (optional).
  5. Copy the Webhook URL and add it to your environment variable file:

.env

Terminal window
DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/..."
  1. Enter your Feishu group chat.
  2. Click the group name > Group Settings > Bot Management.
  3. Add a new Custom Bot and enable Webhooks.
  4. Copy the generated Webhook URL and add it to your environment variable file:

.env

Terminal window
FEISHU_WEBHOOK_URL="https://open.feishu.cn/open-apis/bot/v2/hook/..."

If you are setting up your environment, you can now return to the Environment Configuration document and continue. The remainder of this document can be read later.

Environment configuration set environment variables


Discord notifications are sent as rich messages with green colors and structured fields for high readability.

Feishu notifications are sent as plain-text messages with all purchase details displayed clearly.

ShipSaaS supports extending and integrating new notification channels:

  1. Create a new file in the src/notification/provider directory (e.g., slack.ts).
  2. Implement the NotificationProvider interface:

src/notification/provider/slack.ts

import type {
NotificationProvider,
SendPaymentNotificationParams,
} from '../types';
export class SlackProvider implements NotificationProvider {
private webhookUrl: string;
constructor() {
const webhookUrl = process.env.SLACK_WEBHOOK_URL;
if (!webhookUrl) throw new Error('SLACK_WEBHOOK_URL is required.');
this.webhookUrl = webhookUrl;
}
getProviderName(): string {
return 'slack';
}
async sendPaymentNotification(
params: SendPaymentNotificationParams
): Promise<void> {
const { sessionId, customerId, userName, amount } = params;
try {
// Your Slack message implementation
await fetch(this.webhookUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
text: `🎉 New Purchase\nUsername: ${userName}\nAmount: $${amount.toFixed(2)}`,
}),
});
} catch (error) {
console.error('Failed to send Slack notification:', error);
}
}
}
  1. Register the new notification channel in the providerRegistry in src/notification/index.ts:

src/notification/index.ts

import { SlackProvider } from './provider/slack';
const providerRegistry: Record<NotificationProviderName, ProviderFactory> = {
discord: () => new DiscordProvider(),
feishu: () => new FeishuProvider(),
slack: () => new SlackProvider(),
};
  1. Choose your new notification channel in websiteConfig:

src/config/website.ts

notification: {
enable: true,
provider: 'slack',
},

Now that you know how to use notifications in ShipSaaS, explore these related topics: