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;
|
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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user