LogoTanStarter Docs
LogoTanStarter Docs
HomepageIntroductionCodebaseGetting StartedEnvironments
Configuration
Deployment

Integrations

CloudflareDatabaseAuthenticationEmailNewsletterStoragePaymentNotificationsAnalyticsChatboxAffiliates

Customization

MetadataPagesLanding PageBlogComponentsUser ManagementAPI Key Management

Codebase

Project StructureFormatting & LintingEditor SetupUpdating the Codebase
X (Twitter)

Notifications

Learn how to set up and use notifications in TanStarter

TanStarter supports sending notifications when users successfully complete a payment. This allows your team to receive real-time order alerts in their tools.

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

Setup

Enable Notification Channel

Configure the notification provider in src/config/website.ts:

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

Configure Webhook URL

Based on the notification channel you selected, configure the corresponding Webhook URL:

  1. Go to your Discord server and open 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 avatar for the webhook (optional)
  5. Copy the Webhook URL and add it to your .env file:
.env
DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/..."
  1. Go to 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 .env file:
.env
FEISHU_WEBHOOK_URL="https://open.feishu.cn/open-apis/bot/v2/hook/..."

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

Environment Configuration

Set up environment variables


Notification Message Examples

Discord Message

Discord notifications are sent as messages with green color and structured fields for easy reading.

Discord Message

Feishu Message

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

Feishu Message

Extending New Notification Channels

TanStarter supports extending with 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 provider in the providerRegistry in 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. Select the new provider in websiteConfig:
src/config/website.ts
notification: {
  enable: true,
  provider: 'slack',
},

References

  • Discord Webhooks Documentation
  • Feishu Webhook Documentation

Next Steps

Now that you understand how to use notifications in TanStarter, you might want to explore these related features:

Email

Configure email services

Authentication

Configure user authentication

Analytics

Configure analytics services

Storage

Configure storage services

Table of Contents

Setup
Enable Notification Channel
Configure Webhook URL
Notification Message Examples
Discord Message
Feishu Message
Extending New Notification Channels
References
Next Steps