@deckasoft/waify 0.3.8 → 0.3.10
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.
- package/dist/cli/index.js +35 -4
- 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,47 @@ var registerSetup = (program2) => {
|
|
|
1096
1097
|
},
|
|
1097
1098
|
body: JSON.stringify({ name: "waify" })
|
|
1098
1099
|
}, 1e4);
|
|
1099
|
-
|
|
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
|
-
|
|
1103
|
-
|
|
1120
|
+
spawnSync(
|
|
1121
|
+
"docker",
|
|
1122
|
+
[
|
|
1123
|
+
"compose",
|
|
1124
|
+
"-f",
|
|
1125
|
+
composePath(),
|
|
1126
|
+
"exec",
|
|
1127
|
+
"-T",
|
|
1128
|
+
"openwa-api",
|
|
1129
|
+
"sh",
|
|
1130
|
+
"-c",
|
|
1131
|
+
"rm -f /app/data/sessions/session-waify/Singleton*"
|
|
1132
|
+
],
|
|
1133
|
+
{ encoding: "utf-8" }
|
|
1134
|
+
);
|
|
1104
1135
|
console.warn("Starting WhatsApp engine...");
|
|
1105
1136
|
const startRes = await fetchWithTimeout(`${baseUrl}/api/sessions/${sessionId}/start`, {
|
|
1106
1137
|
method: "POST",
|
|
1107
1138
|
headers: { "X-API-Key": openwaApiKey }
|
|
1108
1139
|
}, 1e4);
|
|
1109
|
-
if (!startRes.ok) {
|
|
1140
|
+
if (!startRes.ok && startRes.status !== 400) {
|
|
1110
1141
|
throw new Error(`Failed to start session: ${startRes.status} ${startRes.statusText}`);
|
|
1111
1142
|
}
|
|
1112
1143
|
console.warn("Waiting for QR code...");
|