-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelegram.js
More file actions
48 lines (39 loc) · 1.51 KB
/
telegram.js
File metadata and controls
48 lines (39 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const site = require('../isite')({});
const apiId = 25389950;
const apiHash = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
const session = new site.telegram.sessions.StoreSession('telegram-data');
const rl = site.readline.createInterface({
input: process.stdin,
output: process.stdout,
});
(async () => {
console.log('Loading interactive example...');
const client = site.connectTelegramClient(session, apiId, apiHash, {
connectionRetries: 5,
});
await client.start({
phoneNumber: async () => new Promise((resolve) => rl.question('Please enter your number: ', resolve)),
password: async () => new Promise((resolve) => rl.question('Please enter your password: ', resolve)),
phoneCode: async () => new Promise((resolve) => rl.question('Please enter the code you received: ', resolve)),
onError: (err) => console.log(err),
});
console.log('You should now be connected.');
client.session.save();
await client.connect();
if (await client.checkAuthorization()) {
console.log('I am logged in!');
} else {
console.log('I am connected to telegram servers but not logged in with any account/bot');
}
client.addEventHandler(async (e) => {
console.log(e);
if (e.message) {
if (e.message.message.like('*hello*')) {
let chat = await client.getInputEntity(e.message.peerId);
let res = await client.sendMessage(chat, { message: 'Hello , iam busy now ' });
console.log(res);
}
}
});
// await client.sendMessage('me', { message: 'Hello!' });
})();