コンテンツにスキップ

検索はプロダクションビルドでのみ利用可能です。 ローカルでテストするには、サイトをビルドしてプレビューしてください。

プッシュ通知

プッシュ通知は Web Push ProtocolVAPID (Voluntary Application Server Identification) を使用して、ブラウザにネイティブ通知を送信します。



Bell RPC: getVapidKey()
→ { publicKey: string }

ブラウザでのサブスクリプション

Section titled “ブラウザでのサブスクリプション”
// Service Worker 登録
const registration = await navigator.serviceWorker.ready;
// Push サブスクリプション作成
const subscription = await registration.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: urlBase64ToUint8Array(publicKey)
});
// サーバーに登録
const { endpoint, keys } = subscription.toJSON();
await registerPushDevice({
shopId,
endpoint,
p256dh: keys.p256dh,
auth: keys.auth,
deviceName: navigator.userAgent,
registeredBy: userId,
registeredByName: userName
});
フィールド説明
endpointPush Service のエンドポイント URL
p256dhクライアント公開鍵(P-256 DH)
auth認証シークレット
deviceNameデバイス名(UserAgent)
registeredBy登録者のユーザー ID

ステータス処理
201送信成功
410 Goneサブスクリプション削除(ブラウザで解除済み)
429リトライ対象(レート制限)
5xxリトライ対象(サーバーエラー)

PUSH メッセージは予約送信が可能です。

Bell RPC: sendPushMessage({
targetUserId, targetType, title, body,
url?, priority?, scheduledAt, createdBy
})
条件動作
scheduledAt が8時間以内即座にキューへ投入(delaySeconds 付き)
scheduledAt が8時間以降DB に保存、Cron でキューイング

Cron トリガー(毎時0分)が scheduledAt <= NOW + 8h の未送信メッセージを検出してキューに投入します。


店舗ごとに複数の PUSH デバイスを登録できます。

Bell RPC: registerShopPushDevice({ shopId, endpoint, p256dh, auth, ... })
Bell RPC: removeShopPushDevice({ id })
Bell RPC: updateShopPushCategories({ id, categories })

ユーザー単位の PUSH サブスクリプション管理です。

Bell RPC: subscribe({ userId, userType, endpoint, p256dh, auth, ... })
Bell RPC: unsubscribe({ endpoint })
Bell RPC: listSubscriptions({ userId })
Bell RPC: updateSubscriptionSettings({ id, settings })
Bell RPC: deleteSubscription({ id })

各デバイスにテスト通知を送信できます。

Bell RPC: sendShopTestNotification({
shopId,
channel: 'push',
targetId: subscriptionId
})