@inetafrica/open-claudia 1.0.1 → 1.0.2
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/package.json +1 -1
- package/setup.js +25 -6
package/package.json
CHANGED
package/setup.js
CHANGED
|
@@ -89,8 +89,17 @@ function getUpdatesForChatId(token) {
|
|
|
89
89
|
try {
|
|
90
90
|
const json = JSON.parse(data);
|
|
91
91
|
if (json.ok && json.result.length > 0) {
|
|
92
|
-
const
|
|
93
|
-
|
|
92
|
+
const msg = json.result[json.result.length - 1].message;
|
|
93
|
+
if (msg?.chat?.id) {
|
|
94
|
+
resolve({
|
|
95
|
+
chatId: String(msg.chat.id),
|
|
96
|
+
firstName: msg.from?.first_name || "",
|
|
97
|
+
lastName: msg.from?.last_name || "",
|
|
98
|
+
username: msg.from?.username || "",
|
|
99
|
+
});
|
|
100
|
+
} else {
|
|
101
|
+
resolve(null);
|
|
102
|
+
}
|
|
94
103
|
} else {
|
|
95
104
|
resolve(null);
|
|
96
105
|
}
|
|
@@ -271,19 +280,29 @@ async function main() {
|
|
|
271
280
|
|
|
272
281
|
console.log(" Now send any message to your bot in Telegram...");
|
|
273
282
|
let chatId = null;
|
|
283
|
+
let userInfo = null;
|
|
274
284
|
for (let i = 0; i < 30; i++) {
|
|
275
|
-
|
|
276
|
-
if (
|
|
285
|
+
userInfo = await getUpdatesForChatId(token);
|
|
286
|
+
if (userInfo) break;
|
|
277
287
|
process.stdout.write(".");
|
|
278
288
|
await new Promise((r) => setTimeout(r, 2000));
|
|
279
289
|
}
|
|
280
290
|
console.log("");
|
|
281
291
|
|
|
282
|
-
if (!
|
|
292
|
+
if (!userInfo) {
|
|
283
293
|
console.log(" Didn't receive a message. Enter chat ID manually:");
|
|
284
294
|
chatId = await ask(" Chat ID: ");
|
|
285
295
|
} else {
|
|
286
|
-
|
|
296
|
+
const name = [userInfo.firstName, userInfo.lastName].filter(Boolean).join(" ");
|
|
297
|
+
const handle = userInfo.username ? ` (@${userInfo.username})` : "";
|
|
298
|
+
console.log(` Message received from: ${name}${handle}`);
|
|
299
|
+
console.log(` Chat ID: ${userInfo.chatId}`);
|
|
300
|
+
const approve = await ask(`\n Authorize this user? (y/n) [y]: `);
|
|
301
|
+
if (approve.toLowerCase() === "n") {
|
|
302
|
+
console.log(" Declined. Send a message from the correct account and run setup again.");
|
|
303
|
+
process.exit(1);
|
|
304
|
+
}
|
|
305
|
+
chatId = userInfo.chatId;
|
|
287
306
|
}
|
|
288
307
|
|
|
289
308
|
// Test sending
|