> ## Documentation Index
> Fetch the complete documentation index at: https://docs.shipthing.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 通知

> 为用户提供的应用内通知功能。

ShipThing 提供了一个通知包，允许您向用户发送应用内通知。默认情况下，它使用 [Knock](https://knock.app/)，这是一个支持应用内、电子邮件、短信、推送和聊天通知的跨渠道通知平台。Knock 允许您将通知逻辑和模板集中在一个地方，并通过分支、批处理、节流、延迟和条件发送等功能[编排复杂的工作流程](https://docs.knock.app/designing-workflows/overview)。

## 设置

要使用通知包，您需要按照 `zh/packages/notifications/keys.ts` 文件中的说明将所需的环境变量添加到您的项目中。

## 应用内通知中心

要渲染应用内通知中心，请从 `@repo/notifications` 包中导入 `NotificationsTrigger` 组件并在您的应用中使用它。我们已经在示例应用的侧边栏中添加了这个组件：

```tsx apps/app/app/(authenticated)/components/sidebar.tsx theme={"system"}
import { NotificationsTrigger } from '@repo/notifications/components/trigger';

<NotificationsTrigger>
  <Button variant="ghost" size="icon" className="shrink-0">
    <BellIcon size={16} className="text-muted-foreground" />
  </Button>
</NotificationsTrigger>
```

按下按钮将打开应用内通知中心，显示当前用户的所有通知。

## 发送通知

Knock 使用工作流程发送通知。要发送应用内通知，请在 Knock 仪表板中创建一个新的[工作流程](https://docs.knock.app/concepts/workflows)，该工作流程使用[`应用内`渠道提供程序](https://docs.knock.app/integrations/in-app/knock)并创建相应的消息模板。

然后您可以在应用中为特定用户[触发该工作流程](https://docs.knock.app/send-notifications/triggering-workflows)，传入必要的数据来填充消息模板：

```tsx notify.ts theme={"system"}
import { notifications } from '@repo/notifications';

await notifications.workflows.trigger('workflow-key', {
  recipients: [{
    id: 'user-id',
    email: 'user-email',
  }],
  data: {
    message: 'Hello, world!',
  },
});
```

## 多渠道通知

使用 Knock，您可以向工作流程添加额外的渠道提供程序，通过电子邮件、短信、推送或聊天发送通知。为此，请在 Knock 仪表板中创建一个新的[渠道提供程序](https://docs.knock.app/integrations)，按照该提供程序的配置说明进行操作，并将其作为渠道步骤添加到您的工作流程中。
