본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

알림

원문 보기 위키 갱신

알림 (Notification / XNotification)

페이지 바깥에 표시되는 시스템 수준 알림을 보낼 수 있는 컴포넌트예요.

출처: 문서

본문

언제 사용하나요?

  • Agent가 복잡한 작업을 수행하는 동안 시스템 수준 애플리케이션 알림을 푸시해서 사용자가 작업 진행 상황을 계속 알 수 있게 할 때 사용해요.
  • 운영 체제의 알림 권한에 의해 제어되므로 약한(weak) 알림에만 사용해요.

주의

  • Notification은 시스템 애플리케이션 알림이라 운영 체제의 알림 권한에 의해 제어돼요. 시스템 알림 권한이 꺼져 있으면 XNotification의 open 메서드 호출은 아무 효과가 없어요. 시스템 권한 설정.
  • XNotification은 window.Notification을 확장해 구현됐어요. 브라우저 환경이 Notification을 지원하지 않으면 XNotification의 메서드 호출은 아무 효과가 없어요.
  • XNotification 알림의 스타일과 효과는 현재 브라우저 환경의 Notification 지원 수준을 따라가요. 예를 들어 dir 속성은 대부분의 브라우저에서 무시돼요.
  • XNotification은 현재 인스턴스 아래의 알림 닫기만 관리해요. 인스턴스가 바뀌면(예: 브라우저 페이지가 새로 고침되면) 이미 보낸 알림을 관리하고 닫을 능력은 없어요.

코드 데모

데모는 원문 문서에서 확인할 수 있어요.

API

알림을 성공적으로 보내려면 현재 도메인에 알림 권한이 부여되어 있는지 먼저 확인해야 해요.

XNotification

속성 설명 타입 기본값 버전
permission 현재 origin에 대해 사용자가 웹 알림 표시 권한을 허락했는지 나타내요 NotificationPermission - -
requestPermission 현재 origin에 대한 알림 표시 권한을 사용자에게 요청해요 ()=> Promise</NotificationPermission/> - -
open 사용자에게 알림을 푸시해요 (config: XNotificationOpenArgs)=> void - -
close 푸시된 알림을 닫아요. tag 목록을 넘겨 특정 알림만 닫을 수 있고, 인자 없이 호출하면 전부 닫아요 (config?: string[])=> void - -

NotificationPermission

type NotificationPermission =
  | 'granted' // The user has explicitly granted the current origin permission to display system notifications.
  | 'denied' // The user has explicitly denied the current origin permission to display system notifications.
  | 'default'; // The user's decision is unknown; in this case, the application behaves as if the permission was "denied".

XNotificationOpenArgs

type XNotificationOpenArgs = {
  openConfig: NotificationOptions & {
    title: string;
    onClick?: (event: Event, close?: Notification['close']) => void;
    onClose?: (event: Event) => void;
    onError?: (event: Event) => void;
    onShow?: (event: Event) => void;
    duration?: number;
  };
  closeConfig: NotificationOptions['tag'][];
};

NotificationOptions

interface NotificationOptions {
  badge?: string;
  body?: string;
  data?: any;
  dir?: NotificationDirection;
  icon?: string;
  lang?: string;
  requireInteraction?: boolean;
  silent?: boolean | null;
  tag?: string;
}

useNotification

type useNotification = [
  { permission: XNotification['permission'] },
  {
    open: XNotification['open'];
    close: XNotification['close'];
    requestPermission: XNotification['requestPermission'];
  },
];

시스템 권한 설정

Windows에서 Notification 설정 변경하기

Windows 버전에 따라 설정 경로가 조금씩 달라요. 대략적인 경로는 다음과 같아요: "시작" 메뉴 > "설정" > "시스템" > 왼쪽에서 "알림 및 작업" 선택. 이후 전역 알림과 애플리케이션 알림을 조정할 수 있어요.

Mac에서 Notification 설정 변경하기

Mac에서는 "알림" 설정으로 알림을 받고 싶지 않은 시간대를 지정하고, "알림 센터"에 알림이 표시되는 방식을 제어할 수 있어요. 이 설정을 바꾸려면 "Apple" 메뉴 > "시스템 설정"을 열고, 사이드바에서 "알림"을 클릭하세요(아래로 스크롤해야 할 수 있어요).

FAQ

현재 origin에 대한 시스템 알림 표시 권한을 받았고 onShow 콜백도 트리거됐는데, 푸시된 알림이 표시되지 않는 이유는?

Notification은 시스템 수준 기능이에요. 사용 중인 기기에서 브라우저 애플리케이션의 알림이 켜져 있는지 확인하세요.

더 알아보기

대화와 메시지를 관리하는 UI는 Conversations 문서를, 파일을 카드 형태로 보여 주는 방법은 파일 카드 (FileCard) 문서를 참고해요.