@stackmemoryai/stackmemory 0.5.10 → 0.5.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ const __filename = __fileURLToPath(import.meta.url);
4
4
  const __dirname = __pathDirname(__filename);
5
5
  import { createServer } from "http";
6
6
  import { parse as parseUrl } from "url";
7
- import { existsSync, writeFileSync, mkdirSync } from "fs";
7
+ import { existsSync, writeFileSync, mkdirSync, readFileSync } from "fs";
8
8
  import { join } from "path";
9
9
  import { homedir } from "os";
10
10
  import { processIncomingResponse, loadSMSConfig } from "./sms-notify.js";
@@ -85,7 +85,7 @@ function startWebhookServer(port = 3456) {
85
85
  res.end(JSON.stringify({ status: "ok" }));
86
86
  return;
87
87
  }
88
- if (url.pathname === "/sms" && req.method === "POST") {
88
+ if ((url.pathname === "/sms" || url.pathname === "/sms/incoming" || url.pathname === "/webhook") && req.method === "POST") {
89
89
  let body = "";
90
90
  req.on("data", (chunk) => {
91
91
  body += chunk;
@@ -106,6 +106,35 @@ function startWebhookServer(port = 3456) {
106
106
  });
107
107
  return;
108
108
  }
109
+ if (url.pathname === "/sms/status" && req.method === "POST") {
110
+ let body = "";
111
+ req.on("data", (chunk) => {
112
+ body += chunk;
113
+ });
114
+ req.on("end", () => {
115
+ try {
116
+ const payload = parseFormData(body);
117
+ console.log(
118
+ `[sms-webhook] Status update: ${payload["MessageSid"]} -> ${payload["MessageStatus"]}`
119
+ );
120
+ const statusPath = join(
121
+ homedir(),
122
+ ".stackmemory",
123
+ "sms-status.json"
124
+ );
125
+ const statuses = existsSync(statusPath) ? JSON.parse(readFileSync(statusPath, "utf8")) : {};
126
+ statuses[payload["MessageSid"]] = payload["MessageStatus"];
127
+ writeFileSync(statusPath, JSON.stringify(statuses, null, 2));
128
+ res.writeHead(200, { "Content-Type": "text/plain" });
129
+ res.end("OK");
130
+ } catch (err) {
131
+ console.error("[sms-webhook] Status error:", err);
132
+ res.writeHead(500);
133
+ res.end("Error");
134
+ }
135
+ });
136
+ return;
137
+ }
109
138
  if (url.pathname === "/status") {
110
139
  const config = loadSMSConfig();
111
140
  res.writeHead(200, { "Content-Type": "application/json" });
@@ -123,8 +152,13 @@ function startWebhookServer(port = 3456) {
123
152
  );
124
153
  server.listen(port, () => {
125
154
  console.log(`[sms-webhook] Server listening on port ${port}`);
126
- console.log(`[sms-webhook] Webhook URL: http://localhost:${port}/sms`);
127
- console.log(`[sms-webhook] Configure this URL in Twilio console`);
155
+ console.log(
156
+ `[sms-webhook] Incoming messages: http://localhost:${port}/sms/incoming`
157
+ );
158
+ console.log(
159
+ `[sms-webhook] Status callback: http://localhost:${port}/sms/status`
160
+ );
161
+ console.log(`[sms-webhook] Configure these URLs in Twilio console`);
128
162
  });
129
163
  }
130
164
  function smsWebhookMiddleware(req, res) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/hooks/sms-webhook.ts"],
4
- "sourcesContent": ["/**\n * SMS Webhook Handler for receiving Twilio responses\n * Can run as standalone server or integrate with existing Express app\n */\n\nimport { createServer, IncomingMessage, ServerResponse } from 'http';\nimport { parse as parseUrl } from 'url';\nimport { existsSync, writeFileSync, mkdirSync } from 'fs';\nimport { join } from 'path';\nimport { homedir } from 'os';\nimport { processIncomingResponse, loadSMSConfig } from './sms-notify.js';\nimport { queueAction } from './sms-action-runner.js';\n\ninterface TwilioWebhookPayload {\n From: string;\n To: string;\n Body: string;\n MessageSid: string;\n}\n\nfunction parseFormData(body: string): Record<string, string> {\n const params = new URLSearchParams(body);\n const result: Record<string, string> = {};\n params.forEach((value, key) => {\n result[key] = value;\n });\n return result;\n}\n\n// Store response for Claude hook to pick up\nfunction storeLatestResponse(\n promptId: string,\n response: string,\n action?: string\n): void {\n const dir = join(homedir(), '.stackmemory');\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true });\n }\n const responsePath = join(dir, 'sms-latest-response.json');\n writeFileSync(\n responsePath,\n JSON.stringify({\n promptId,\n response,\n action,\n timestamp: new Date().toISOString(),\n })\n );\n}\n\nexport function handleSMSWebhook(payload: TwilioWebhookPayload): {\n response: string;\n action?: string;\n queued?: boolean;\n} {\n const { From, Body } = payload;\n\n console.log(`[sms-webhook] Received from ${From}: ${Body}`);\n\n const result = processIncomingResponse(From, Body);\n\n if (!result.matched) {\n if (result.prompt) {\n return {\n response: `Invalid response. Expected: ${result.prompt.options.map((o) => o.key).join(', ')}`,\n };\n }\n return { response: 'No pending prompt found.' };\n }\n\n // Store response for Claude hook\n storeLatestResponse(\n result.prompt?.id || 'unknown',\n result.response || Body,\n result.action\n );\n\n // Queue action for execution (instead of immediate execution)\n if (result.action) {\n const actionId = queueAction(\n result.prompt?.id || 'unknown',\n result.response || Body,\n result.action\n );\n console.log(`[sms-webhook] Queued action ${actionId}: ${result.action}`);\n\n return {\n response: `Got it! Queued action: ${result.action.substring(0, 30)}...`,\n action: result.action,\n queued: true,\n };\n }\n\n return {\n response: `Received: ${result.response}. Next action will be triggered.`,\n };\n}\n\n// TwiML response helper\nfunction twimlResponse(message: string): string {\n return `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Response>\n <Message>${escapeXml(message)}</Message>\n</Response>`;\n}\n\nfunction escapeXml(str: string): string {\n return str\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;')\n .replace(/'/g, '&apos;');\n}\n\n// Standalone webhook server\nexport function startWebhookServer(port: number = 3456): void {\n const server = createServer(\n async (req: IncomingMessage, res: ServerResponse) => {\n const url = parseUrl(req.url || '/', true);\n\n // Health check\n if (url.pathname === '/health') {\n res.writeHead(200, { 'Content-Type': 'application/json' });\n res.end(JSON.stringify({ status: 'ok' }));\n return;\n }\n\n // SMS webhook endpoint\n if (url.pathname === '/sms' && req.method === 'POST') {\n let body = '';\n req.on('data', (chunk) => {\n body += chunk;\n });\n\n req.on('end', () => {\n try {\n const payload = parseFormData(\n body\n ) as unknown as TwilioWebhookPayload;\n const result = handleSMSWebhook(payload);\n\n res.writeHead(200, { 'Content-Type': 'text/xml' });\n res.end(twimlResponse(result.response));\n } catch (err) {\n console.error('[sms-webhook] Error:', err);\n res.writeHead(500, { 'Content-Type': 'text/xml' });\n res.end(twimlResponse('Error processing message'));\n }\n });\n return;\n }\n\n // Status endpoint\n if (url.pathname === '/status') {\n const config = loadSMSConfig();\n res.writeHead(200, { 'Content-Type': 'application/json' });\n res.end(\n JSON.stringify({\n enabled: config.enabled,\n pendingPrompts: config.pendingPrompts.length,\n })\n );\n return;\n }\n\n res.writeHead(404);\n res.end('Not found');\n }\n );\n\n server.listen(port, () => {\n console.log(`[sms-webhook] Server listening on port ${port}`);\n console.log(`[sms-webhook] Webhook URL: http://localhost:${port}/sms`);\n console.log(`[sms-webhook] Configure this URL in Twilio console`);\n });\n}\n\n// Express middleware for integration\nexport function smsWebhookMiddleware(\n req: { body: TwilioWebhookPayload },\n res: { type: (t: string) => void; send: (s: string) => void }\n): void {\n const result = handleSMSWebhook(req.body);\n res.type('text/xml');\n res.send(twimlResponse(result.response));\n}\n\n// CLI entry\nif (process.argv[1]?.endsWith('sms-webhook.js')) {\n const port = parseInt(process.env['SMS_WEBHOOK_PORT'] || '3456', 10);\n startWebhookServer(port);\n}\n"],
5
- "mappings": ";;;;AAKA,SAAS,oBAAqD;AAC9D,SAAS,SAAS,gBAAgB;AAClC,SAAS,YAAY,eAAe,iBAAiB;AACrD,SAAS,YAAY;AACrB,SAAS,eAAe;AACxB,SAAS,yBAAyB,qBAAqB;AACvD,SAAS,mBAAmB;AAS5B,SAAS,cAAc,MAAsC;AAC3D,QAAM,SAAS,IAAI,gBAAgB,IAAI;AACvC,QAAM,SAAiC,CAAC;AACxC,SAAO,QAAQ,CAAC,OAAO,QAAQ;AAC7B,WAAO,GAAG,IAAI;AAAA,EAChB,CAAC;AACD,SAAO;AACT;AAGA,SAAS,oBACP,UACA,UACA,QACM;AACN,QAAM,MAAM,KAAK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A,UACxC,CAAC;AAAA,QACH;AACA;AAAA,MACF;AAEA,UAAI,UAAU,GAAG;AACjB,UAAI,IAAI,WAAW;AAAA,IACrB;AAAA,EACF;AAEA,SAAO,OAAO,MAAM,MAAM;AACxB,YAAQ,IAAI,0CAA0C,IAAI,EAAE;AAC5D,YAAQ,IAAI,+CAA+C,IAAI,MAAM;AACrE,YAAQ,IAAI,oDAAoD;AAAA,EAClE,CAAC;AACH;AAGO,SAAS,qBACd,KACA,KACM;AACN,QAAM,SAAS,iBAAiB,IAAI,IAAI;AACxC,MAAI,KAAK,UAAU;AACnB,MAAI,KAAK,cAAc,OAAO,QAAQ,CAAC;AACzC;AAGA,IAAI,QAAQ,KAAK,CAAC,GAAG,SAAS,gBAAgB,GAAG;AAC/C,QAAM,OAAO,SAAS,QAAQ,IAAI,kBAAkB,KAAK,QAAQ,EAAE;AACnE,qBAAmB,IAAI;AACzB;",
4
+ "sourcesContent": ["/**\n * SMS Webhook Handler for receiving Twilio responses\n * Can run as standalone server or integrate with existing Express app\n */\n\nimport { createServer, IncomingMessage, ServerResponse } from 'http';\nimport { parse as parseUrl } from 'url';\nimport { existsSync, writeFileSync, mkdirSync, readFileSync } from 'fs';\nimport { join } from 'path';\nimport { homedir } from 'os';\nimport { processIncomingResponse, loadSMSConfig } from './sms-notify.js';\nimport { queueAction } from './sms-action-runner.js';\n\ninterface TwilioWebhookPayload {\n From: string;\n To: string;\n Body: string;\n MessageSid: string;\n}\n\nfunction parseFormData(body: string): Record<string, string> {\n const params = new URLSearchParams(body);\n const result: Record<string, string> = {};\n params.forEach((value, key) => {\n result[key] = value;\n });\n return result;\n}\n\n// Store response for Claude hook to pick up\nfunction storeLatestResponse(\n promptId: string,\n response: string,\n action?: string\n): void {\n const dir = join(homedir(), '.stackmemory');\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true });\n }\n const responsePath = join(dir, 'sms-latest-response.json');\n writeFileSync(\n responsePath,\n JSON.stringify({\n promptId,\n response,\n action,\n timestamp: new Date().toISOString(),\n })\n );\n}\n\nexport function handleSMSWebhook(payload: TwilioWebhookPayload): {\n response: string;\n action?: string;\n queued?: boolean;\n} {\n const { From, Body } = payload;\n\n console.log(`[sms-webhook] Received from ${From}: ${Body}`);\n\n const result = processIncomingResponse(From, Body);\n\n if (!result.matched) {\n if (result.prompt) {\n return {\n response: `Invalid response. Expected: ${result.prompt.options.map((o) => o.key).join(', ')}`,\n };\n }\n return { response: 'No pending prompt found.' };\n }\n\n // Store response for Claude hook\n storeLatestResponse(\n result.prompt?.id || 'unknown',\n result.response || Body,\n result.action\n );\n\n // Queue action for execution (instead of immediate execution)\n if (result.action) {\n const actionId = queueAction(\n result.prompt?.id || 'unknown',\n result.response || Body,\n result.action\n );\n console.log(`[sms-webhook] Queued action ${actionId}: ${result.action}`);\n\n return {\n response: `Got it! Queued action: ${result.action.substring(0, 30)}...`,\n action: result.action,\n queued: true,\n };\n }\n\n return {\n response: `Received: ${result.response}. Next action will be triggered.`,\n };\n}\n\n// TwiML response helper\nfunction twimlResponse(message: string): string {\n return `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Response>\n <Message>${escapeXml(message)}</Message>\n</Response>`;\n}\n\nfunction escapeXml(str: string): string {\n return str\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;')\n .replace(/'/g, '&apos;');\n}\n\n// Standalone webhook server\nexport function startWebhookServer(port: number = 3456): void {\n const server = createServer(\n async (req: IncomingMessage, res: ServerResponse) => {\n const url = parseUrl(req.url || '/', true);\n\n // Health check\n if (url.pathname === '/health') {\n res.writeHead(200, { 'Content-Type': 'application/json' });\n res.end(JSON.stringify({ status: 'ok' }));\n return;\n }\n\n // SMS webhook endpoint (incoming messages)\n if (\n (url.pathname === '/sms' ||\n url.pathname === '/sms/incoming' ||\n url.pathname === '/webhook') &&\n req.method === 'POST'\n ) {\n let body = '';\n req.on('data', (chunk) => {\n body += chunk;\n });\n\n req.on('end', () => {\n try {\n const payload = parseFormData(\n body\n ) as unknown as TwilioWebhookPayload;\n const result = handleSMSWebhook(payload);\n\n res.writeHead(200, { 'Content-Type': 'text/xml' });\n res.end(twimlResponse(result.response));\n } catch (err) {\n console.error('[sms-webhook] Error:', err);\n res.writeHead(500, { 'Content-Type': 'text/xml' });\n res.end(twimlResponse('Error processing message'));\n }\n });\n return;\n }\n\n // Status callback endpoint (delivery status updates)\n if (url.pathname === '/sms/status' && req.method === 'POST') {\n let body = '';\n req.on('data', (chunk) => {\n body += chunk;\n });\n\n req.on('end', () => {\n try {\n const payload = parseFormData(body);\n console.log(\n `[sms-webhook] Status update: ${payload['MessageSid']} -> ${payload['MessageStatus']}`\n );\n\n // Store status for tracking\n const statusPath = join(\n homedir(),\n '.stackmemory',\n 'sms-status.json'\n );\n const statuses: Record<string, string> = existsSync(statusPath)\n ? JSON.parse(readFileSync(statusPath, 'utf8'))\n : {};\n statuses[payload['MessageSid']] = payload['MessageStatus'];\n writeFileSync(statusPath, JSON.stringify(statuses, null, 2));\n\n res.writeHead(200, { 'Content-Type': 'text/plain' });\n res.end('OK');\n } catch (err) {\n console.error('[sms-webhook] Status error:', err);\n res.writeHead(500);\n res.end('Error');\n }\n });\n return;\n }\n\n // Server status endpoint\n if (url.pathname === '/status') {\n const config = loadSMSConfig();\n res.writeHead(200, { 'Content-Type': 'application/json' });\n res.end(\n JSON.stringify({\n enabled: config.enabled,\n pendingPrompts: config.pendingPrompts.length,\n })\n );\n return;\n }\n\n res.writeHead(404);\n res.end('Not found');\n }\n );\n\n server.listen(port, () => {\n console.log(`[sms-webhook] Server listening on port ${port}`);\n console.log(\n `[sms-webhook] Incoming messages: http://localhost:${port}/sms/incoming`\n );\n console.log(\n `[sms-webhook] Status callback: http://localhost:${port}/sms/status`\n );\n console.log(`[sms-webhook] Configure these URLs in Twilio console`);\n });\n}\n\n// Express middleware for integration\nexport function smsWebhookMiddleware(\n req: { body: TwilioWebhookPayload },\n res: { type: (t: string) => void; send: (s: string) => void }\n): void {\n const result = handleSMSWebhook(req.body);\n res.type('text/xml');\n res.send(twimlResponse(result.response));\n}\n\n// CLI entry\nif (process.argv[1]?.endsWith('sms-webhook.js')) {\n const port = parseInt(process.env['SMS_WEBHOOK_PORT'] || '3456', 10);\n startWebhookServer(port);\n}\n"],
5
+ "mappings": ";;;;AAKA,SAAS,oBAAqD;AAC9D,SAAS,SAAS,gBAAgB;AAClC,SAAS,YAAY,eAAe,WAAW,oBAAoB;AACnE,SAAS,YAAY;AACrB,SAAS,eAAe;AACxB,SAAS,yBAAyB,qBAAqB;AACvD,SAAS,mBAAmB;AAS5B,SAAS,cAAc,MAAsC;AAC3D,QAAM,SAAS,IAAI,gBAAgB,IAAI;AACvC,QAAM,SAAiC,CAAC;AACxC,SAAO,QAAQ,CAAC,OAAO,QAAQ;AAC7B,WAAO,GAAG,IAAI;AAAA,EAChB,CAAC;AACD,SAAO;AACT;AAGA,SAAS,oBACP,UACA,UACA,QACM;AACN,QAAM,MAAM,KAAK,QAAQ,GAAG,cAAc;AAC1C,MAAI,CAAC,WAAW,GAAG,GAAG;AACpB,cAAU,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,EACpC;AACA,QAAM,eAAe,KAAK,KAAK,0BAA0B;AACzD;AAAA,IACE;AAAA,IACA,KAAK,UAAU;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,MACA,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,IACpC,CAAC;AAAA,EACH;AACF;AAEO,SAAS,iBAAiB,SAI/B;AACA,QAAM,EAAE,MAAM,KAAK,IAAI;AAEvB,UAAQ,IAAI,+BAA+B,IAAI,KAAK,IAAI,EAAE;AAE1D,QAAM,SAAS,wBAAwB,MAAM,IAAI;AAEjD,MAAI,CAAC,OAAO,SAAS;AACnB,QAAI,OAAO,QAAQ;AACjB,aAAO;AAAA,QACL,UAAU,+BAA+B,OAAO,OAAO,QAAQ,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,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,CAAC;AACD;AAAA,MACF;AAGA,UAAI,IAAI,aAAa,WAAW;AAC9B,cAAM,SAAS,cAAc;AAC7B,YAAI,UAAU,KAAK,EAAE,gBAAgB,mBAAmB,CAAC;AACzD,YAAI;AAAA,UACF,KAAK,UAAU;AAAA,YACb,SAAS,OAAO;AAAA,YAChB,gBAAgB,OAAO,eAAe;AAAA,UACxC,CAAC;AAAA,QACH;AACA;AAAA,MACF;AAEA,UAAI,UAAU,GAAG;AACjB,UAAI,IAAI,WAAW;AAAA,IACrB;AAAA,EACF;AAEA,SAAO,OAAO,MAAM,MAAM;AACxB,YAAQ,IAAI,0CAA0C,IAAI,EAAE;AAC5D,YAAQ;AAAA,MACN,qDAAqD,IAAI;AAAA,IAC3D;AACA,YAAQ;AAAA,MACN,qDAAqD,IAAI;AAAA,IAC3D;AACA,YAAQ,IAAI,sDAAsD;AAAA,EACpE,CAAC;AACH;AAGO,SAAS,qBACd,KACA,KACM;AACN,QAAM,SAAS,iBAAiB,IAAI,IAAI;AACxC,MAAI,KAAK,UAAU;AACnB,MAAI,KAAK,cAAc,OAAO,QAAQ,CAAC;AACzC;AAGA,IAAI,QAAQ,KAAK,CAAC,GAAG,SAAS,gBAAgB,GAAG;AAC/C,QAAM,OAAO,SAAS,QAAQ,IAAI,kBAAkB,KAAK,QAAQ,EAAE;AACnE,qBAAmB,IAAI;AACzB;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackmemoryai/stackmemory",
3
- "version": "0.5.10",
3
+ "version": "0.5.11",
4
4
  "description": "Lossless memory runtime for AI coding tools - organizes context as a call stack instead of linear chat logs, with team collaboration and infinite retention",
5
5
  "engines": {
6
6
  "node": ">=20.0.0",
@@ -0,0 +1,103 @@
1
+ #!/bin/bash
2
+ # Auto-setup for StackMemory WhatsApp/SMS webhook loop
3
+
4
+ set -e
5
+
6
+ WEBHOOK_PORT="${1:-3456}"
7
+ TWILIO_ACCOUNT_SID="${TWILIO_ACCOUNT_SID}"
8
+ TWILIO_AUTH_TOKEN="${TWILIO_AUTH_TOKEN}"
9
+
10
+ echo "=== StackMemory Webhook Setup ==="
11
+ echo ""
12
+
13
+ # Check dependencies
14
+ if ! command -v ngrok &> /dev/null; then
15
+ echo "Installing ngrok..."
16
+ if command -v brew &> /dev/null; then
17
+ brew install ngrok
18
+ else
19
+ echo "Please install ngrok: https://ngrok.com/download"
20
+ exit 1
21
+ fi
22
+ fi
23
+
24
+ # Check Twilio credentials
25
+ if [ -z "$TWILIO_ACCOUNT_SID" ] || [ -z "$TWILIO_AUTH_TOKEN" ]; then
26
+ echo "Error: Set TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN"
27
+ exit 1
28
+ fi
29
+
30
+ # Kill any existing processes
31
+ pkill -f "notify webhook" 2>/dev/null || true
32
+ pkill -f "ngrok http $WEBHOOK_PORT" 2>/dev/null || true
33
+ sleep 1
34
+
35
+ # Start webhook server in background
36
+ echo "Starting webhook server on port $WEBHOOK_PORT..."
37
+ stackmemory notify webhook -p "$WEBHOOK_PORT" > /tmp/webhook.log 2>&1 &
38
+ WEBHOOK_PID=$!
39
+ sleep 2
40
+
41
+ # Start ngrok in background
42
+ echo "Starting ngrok tunnel..."
43
+ ngrok http "$WEBHOOK_PORT" --log=stdout > /tmp/ngrok.log 2>&1 &
44
+ NGROK_PID=$!
45
+ sleep 3
46
+
47
+ # Get ngrok public URL
48
+ NGROK_URL=$(curl -s http://localhost:4040/api/tunnels | grep -o '"public_url":"https://[^"]*' | head -1 | cut -d'"' -f4)
49
+
50
+ if [ -z "$NGROK_URL" ]; then
51
+ echo "Error: Could not get ngrok URL. Check /tmp/ngrok.log"
52
+ exit 1
53
+ fi
54
+
55
+ WEBHOOK_URL="${NGROK_URL}/sms/incoming"
56
+ echo ""
57
+ echo "Webhook URL: $WEBHOOK_URL"
58
+
59
+ # Configure Twilio WhatsApp sandbox webhook
60
+ echo ""
61
+ echo "Configuring Twilio WhatsApp sandbox..."
62
+
63
+ # Get sandbox configuration
64
+ SANDBOX_RESPONSE=$(curl -s "https://api.twilio.com/2010-04-01/Accounts/${TWILIO_ACCOUNT_SID}/Sandbox.json" \
65
+ -u "${TWILIO_ACCOUNT_SID}:${TWILIO_AUTH_TOKEN}" 2>/dev/null)
66
+
67
+ if echo "$SANDBOX_RESPONSE" | grep -q "sms_url"; then
68
+ # Update sandbox webhook URL
69
+ curl -s -X POST "https://api.twilio.com/2010-04-01/Accounts/${TWILIO_ACCOUNT_SID}/Sandbox.json" \
70
+ -u "${TWILIO_ACCOUNT_SID}:${TWILIO_AUTH_TOKEN}" \
71
+ -d "SmsUrl=${WEBHOOK_URL}" \
72
+ -d "SmsMethod=POST" > /dev/null
73
+ echo "Sandbox webhook configured!"
74
+ else
75
+ echo "Note: Configure webhook manually in Twilio console:"
76
+ echo " URL: $WEBHOOK_URL"
77
+ echo " https://console.twilio.com/us1/develop/sms/try-it-out/whatsapp-learn"
78
+ fi
79
+
80
+ # Install Claude hook
81
+ echo ""
82
+ echo "Installing Claude response hook..."
83
+ stackmemory notify install-response-hook 2>/dev/null || true
84
+
85
+ # Save PIDs for cleanup
86
+ echo "$WEBHOOK_PID" > /tmp/stackmemory-webhook.pid
87
+ echo "$NGROK_PID" > /tmp/stackmemory-ngrok.pid
88
+
89
+ echo ""
90
+ echo "=== Setup Complete ==="
91
+ echo ""
92
+ echo "Webhook server: http://localhost:$WEBHOOK_PORT (PID: $WEBHOOK_PID)"
93
+ echo "Ngrok tunnel: $NGROK_URL (PID: $NGROK_PID)"
94
+ echo "Webhook URL: $WEBHOOK_URL"
95
+ echo ""
96
+ echo "The loop is now active:"
97
+ echo " 1. Send notification: stackmemory notify review 'Task'"
98
+ echo " 2. User replies via WhatsApp"
99
+ echo " 3. Response queued for action"
100
+ echo " 4. Claude hook processes it"
101
+ echo ""
102
+ echo "To stop: ./scripts/stop-notify-webhook.sh"
103
+ echo "Logs: /tmp/webhook.log, /tmp/ngrok.log"
@@ -0,0 +1,19 @@
1
+ #!/bin/bash
2
+ # Stop StackMemory webhook services
3
+
4
+ echo "Stopping webhook services..."
5
+
6
+ if [ -f /tmp/stackmemory-webhook.pid ]; then
7
+ kill $(cat /tmp/stackmemory-webhook.pid) 2>/dev/null && echo "Webhook server stopped"
8
+ rm /tmp/stackmemory-webhook.pid
9
+ fi
10
+
11
+ if [ -f /tmp/stackmemory-ngrok.pid ]; then
12
+ kill $(cat /tmp/stackmemory-ngrok.pid) 2>/dev/null && echo "Ngrok tunnel stopped"
13
+ rm /tmp/stackmemory-ngrok.pid
14
+ fi
15
+
16
+ pkill -f "notify webhook" 2>/dev/null || true
17
+ pkill -f "ngrok http" 2>/dev/null || true
18
+
19
+ echo "Done"