add a bit of extra code so the client doesnt close prematurely
This commit is contained in:
+17
-2
@@ -42,8 +42,23 @@ import * as telegram from '../telegram/telegram';
|
||||
return;
|
||||
}
|
||||
console.log('Message response:', message);
|
||||
// Wait for 5 seconds
|
||||
await new Promise(resolve => setTimeout(resolve, 5000));
|
||||
let messageSent = false;
|
||||
// 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
|
||||
const logout = await telegram.destroy(client);
|
||||
if (!logout) {
|
||||
|
||||
Reference in New Issue
Block a user