# 2. Check Status Query the status of the ongoing verification session. --- Once the verification process is initialized and you get a requestId, your frontend needs to listen (via SSE) to the stream endpoint to know if the user has sent the message. ### Plan A: SSE Mechanism (Fastest): - Open an EventSource connection to the stream endpoint. - Once you receive the "VERIFIED" status, close the connection and log the user in. ### Fallbacks (Plan B & C): - **Plan B (Polling):** If your hosting environment does not support SSE, you can fall back to traditional polling by making a GET request to /api/verify/status?id=... every 3 seconds. - **Plan C (Webhooks):** For robust server-to-server synchronization, utilize our Webhook system. See the Webhooks section for details. ### Returned Session Statuses: - PENDING: The user has not sent the verification message yet. Keep listening. - VERIFIED: The message was received, and the number is verified. - EXPIRED: The session has timed out (usually 2 minutes after initiation). ## Code Examples ### cURL (SSE) ```javascript curl -N https://[your-domain.com]/api/verify/stream?id=YOUR_REQUEST_ID ``` ### JavaScript (Zero-Delay) ```javascript const checkStatus = (requestId) => { const evtSource = new EventSource(`https://[your-domain.com]/api/verify/stream?id=${requestId}`); evtSource.onmessage = (event) => { const data = JSON.parse(event.data); if (data.status === "VERIFIED") { evtSource.close(); alert("Successfully Verified! ✅"); // Execute login logic here } else if (data.status === "EXPIRED") { evtSource.close(); console.error("Session expired!"); } else if (data.status === "REJECTED") { evtSource.close(); console.error("Rejected:", data.failureReason); } }; evtSource.onerror = () => { evtSource.close(); console.error("EventSource failed."); }; }; ``` ### Node.js (SSE) ```javascript const EventSource = require('eventsource'); const checkStatus = (requestId) => { const evtSource = new EventSource(`https://[your-domain.com]/api/verify/stream?id=${requestId}`); evtSource.onmessage = (event) => { const data = JSON.parse(event.data); if (data.status === 'VERIFIED') { evtSource.close(); console.log('User verified!'); } else if (data.status === 'EXPIRED') { evtSource.close(); console.error('Session expired!'); } else if (data.status === 'REJECTED') { evtSource.close(); console.error('Rejected:', data.failureReason); } }; }; ``` ### Python (SSE) ```javascript import sseclient import requests import json def check_status(request_id): url = f"https://[your-domain.com]/api/verify/stream?id={request_id}" response = requests.get(url, stream=True) client = sseclient.SSEClient(response) for event in client.events(): if not event.data: continue data = json.loads(event.data) status = data.get("status") if status == "VERIFIED": print("Successfully verified!") break elif status == "EXPIRED": print("Session expired!") break elif status == "REJECTED": reason = data.get("failureReason", "Unknown") print(f"Rejected: {reason}") break ```