@deckasoft/waify 0.3.8 → 0.3.9

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.
Files changed (2) hide show
  1. package/dist/cli/index.js +20 -4
  2. package/package.json +1 -1
package/dist/cli/index.js CHANGED
@@ -969,6 +969,7 @@ var SessionResponseSchema = z5.object({
969
969
  id: z5.string().optional(),
970
970
  name: z5.string().optional()
971
971
  });
972
+ var SessionListSchema = z5.array(SessionResponseSchema);
972
973
  var QrResponseSchema = z5.object({
973
974
  qrCode: z5.string().optional()
974
975
  });
@@ -1096,17 +1097,32 @@ var registerSetup = (program2) => {
1096
1097
  },
1097
1098
  body: JSON.stringify({ name: "waify" })
1098
1099
  }, 1e4);
1099
- if (!sessionRes.ok) {
1100
+ let sessionId;
1101
+ if (sessionRes.status === 409) {
1102
+ const listRes = await fetchWithTimeout(`${baseUrl}/api/sessions`, {
1103
+ headers: { "X-API-Key": openwaApiKey }
1104
+ }, 1e4);
1105
+ if (!listRes.ok) {
1106
+ throw new Error(`Failed to list sessions: ${listRes.status} ${listRes.statusText}`);
1107
+ }
1108
+ const sessions = SessionListSchema.parse(await listRes.json());
1109
+ const existing = sessions.find((s) => s.name === "waify");
1110
+ if (!existing?.id) {
1111
+ throw new Error('Session "waify" already exists but could not be retrieved');
1112
+ }
1113
+ sessionId = existing.id;
1114
+ } else if (!sessionRes.ok) {
1100
1115
  throw new Error(`Failed to create session: ${sessionRes.status} ${sessionRes.statusText}`);
1116
+ } else {
1117
+ const sessionData = SessionResponseSchema.parse(await sessionRes.json());
1118
+ sessionId = sessionData.id ?? sessionData.name ?? "waify";
1101
1119
  }
1102
- const sessionData = SessionResponseSchema.parse(await sessionRes.json());
1103
- const sessionId = sessionData.id ?? sessionData.name ?? "waify";
1104
1120
  console.warn("Starting WhatsApp engine...");
1105
1121
  const startRes = await fetchWithTimeout(`${baseUrl}/api/sessions/${sessionId}/start`, {
1106
1122
  method: "POST",
1107
1123
  headers: { "X-API-Key": openwaApiKey }
1108
1124
  }, 1e4);
1109
- if (!startRes.ok) {
1125
+ if (!startRes.ok && startRes.status !== 400) {
1110
1126
  throw new Error(`Failed to start session: ${startRes.status} ${startRes.statusText}`);
1111
1127
  }
1112
1128
  console.warn("Waiting for QR code...");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deckasoft/waify",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "description": "AI-powered daily message sender for WhatsApp, powered by OpenWA",
5
5
  "keywords": [
6
6
  "whatsapp",