UNPKG

plazbot

Version:

Official Plazbot SDK for creating AI agents for WhatsApp, portals, and developers.

20 lines (19 loc) 638 B
import { useState } from 'react'; function generateSessionId() { const ts = Date.now().toString(36); const rand = Math.random().toString(36).substring(2, 9); return `ses_${ts}_${rand}`; } export function useSession(storageKey = 'plazbot_session_id') { const [sessionId] = useState(() => { if (typeof window === 'undefined') return generateSessionId(); const stored = localStorage.getItem(storageKey); if (stored) return stored; const newId = generateSessionId(); localStorage.setItem(storageKey, newId); return newId; }); return sessionId; }