add a bit of extra code so the client doesnt close prematurely

This commit is contained in:
Robyn-Dawn
2024-12-05 14:42:52 +00:00
parent 2343e54a6f
commit e52d54ffe7
+17 -2
View File
@@ -42,8 +42,23 @@ import * as telegram from '../telegram/telegram';
return; return;
} }
console.log('Message response:', message); console.log('Message response:', message);
// Wait for 5 seconds let messageSent = false;
await new Promise(resolve => setTimeout(resolve, 5000)); // Temporarily hook onto the client to wait until it is sent
function listener(u : any) {
if (u?._ === 'updateMessageSendSucceeded') {
console.log('Message sent:', u.message.id);
// check if the client is a client because ts is fussy
if (typeof client === 'object') {
messageSent = true;
client.off('update', listener);
}
}
}
client.on('update', listener);
// Wait until the message is sent
while (!messageSent) {
await new Promise(resolve => setTimeout(resolve, 1000));
}
// Close the client // Close the client
const logout = await telegram.destroy(client); const logout = await telegram.destroy(client);
if (!logout) { if (!logout) {