YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
feat: add GET /contacts to WhatsApp gateway so AI can resolve names to phones
Louis Beaumont60769a74e606
diff --git a/crates/screenpipe-connect/src/whatsapp/gateway.mjs b/crates/screenpipe-connect/src/whatsapp/gateway.mjsindex f1356b6e5..d7bfa0d83 100644--- a/crates/screenpipe-connect/src/whatsapp/gateway.mjs+++ b/crates/screenpipe-connect/src/whatsapp/gateway.mjs@@ -12,7 +12,8 @@// { "type": "http", "port": 3035 }//// HTTP API (Pi curls this directly):-// POST /send { "to": "33612345678", "text": "hello" }+// POST /send { "to": "+33612345678", "text": "hello" }+// GET /contacts returns [{ "id": "33612345678", "name": "John", "phone": "+33612345678" }, ...]// GET /statusimport makeWASocket, { useMultiFileAuthState, DisconnectReason, fetchLatestBaileysVersion } from "@whiskeysockets/baileys";@@ -64,6 +65,33 @@ const server = createServer(async (req, res) => {}}+ if (req.method === "GET" && req.url === "/contacts") {+ if (!sock) {+ res.writeHead(503);+ return res.end(JSON.stringify({ error: "whatsapp not connected" }));+ }+ try {+ const contacts = [];+ const store = sock.store?.contacts || {};+ // sock.store may not be available; use the contacts from the socket directly+ const contactMap = sock.contacts || store;+ for (const [jid, contact] of Object.entries(contactMap)) {+ if (!jid.endsWith("@s.whatsapp.net")) continue;+ const phone = "+" + jid.split("@")[0];+ contacts.push({+ id: jid,+ name: contact.name || contact.notify || contact.verifiedName || phone,+ phone,+ });+ }+ res.writeHead(200);+ return res.end(JSON.stringify(contacts));+ } catch (err) {+ res.writeHead(500);+ return res.end(JSON.stringify({ error: err.message || String(err) }));+ }+ }+if (req.method === "GET" && req.url === "/status") {const me = sock?.user;res.writeHead(200);diff --git a/crates/screenpipe-engine/src/cli/connection.rs b/crates/screenpipe-engine/src/cli/connection.rsindex 6af4ed87c..38956c90f 100644--- a/crates/screenpipe-engine/src/cli/connection.rs+++ b/crates/screenpipe-engine/src/cli/connection.rs@@ -24,9 +24,9 @@ pub async fn handle_connection_command(command: &ConnectionCommand) -> anyhow::R.join("creds.json").exists();let wa_desc = if wa_connected {- "Send messages: curl -X POST http://localhost:3035/send -H 'Content-Type: application/json' -d '{\"to\":\"PHONE\",\"text\":\"MSG\"}'".to_string()+ "WhatsApp messaging. First GET http://localhost:3035/contacts to resolve names to phone numbers, then POST http://localhost:3035/send with {\"to\":\"+PHONE\",\"text\":\"MSG\"}".to_string()} else {- "Pair via Settings > Connections in the desktop app".to_string()+ "Not paired. User must pair via Settings > Connections in the desktop app first.".to_string()};if *use_json {@@ -73,13 +73,13 @@ pub async fn handle_connection_command(command: &ConnectionCommand) -> anyhow::Rjson!({"id": "whatsapp","connected": true,- "description": "Send messages: curl -X POST http://localhost:3035/send -H 'Content-Type: application/json' -d '{\"to\":\"PHONE\",\"text\":\"MSG\"}'"+ "description": "WhatsApp messaging. First GET http://localhost:3035/contacts to resolve names to phone numbers, then POST http://localhost:3035/send with {\"to\":\"+PHONE\",\"text\":\"MSG\"}"})} else {json!({"id": "whatsapp","connected": false,- "description": "Pair via Settings > Connections in the desktop app"+ "description": "Not paired. User must pair via Settings > Connections in the desktop app first."})};if *use_json {diff --git a/crates/screenpipe-engine/src/connections_api.rs b/crates/screenpipe-engine/src/connections_api.rsindex 252966d75..bd6dc73c8 100644--- a/crates/screenpipe-engine/src/connections_api.rs+++ b/crates/screenpipe-engine/src/connections_api.rs@@ -53,8 +53,8 @@ async fn list_connections(State(state): State<ConnectionsState>) -> Json<Value>let wa_connected = matches!(wa_status, screenpipe_connect::whatsapp::WhatsAppStatus::Connected { .. });let wa_desc = if let Some(port) = wa_port {format!(- "Send WhatsApp messages. curl -X POST http://localhost:{}/send -H 'Content-Type: application/json' -d '{{\"to\":\"PHONE\",\"text\":\"MESSAGE\"}}'",- port+ "WhatsApp messaging. First GET http://localhost:{}/contacts to resolve names to phone numbers, then POST http://localhost:{}/send with {{\"to\":\"+PHONE\",\"text\":\"MSG\"}}",+ port, port)} else {"Connect your personal WhatsApp via QR code pairing in Settings > Connections.".to_string()