-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBotClass.js
More file actions
32 lines (29 loc) · 1005 Bytes
/
Copy pathBotClass.js
File metadata and controls
32 lines (29 loc) · 1005 Bytes
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
class Bot {
init(TOKEN) {
return new Promise((resolve, reject) => {
let url = `https://api.telegram.org/bot${TOKEN}/getMe`
request(url, (error, r, body) => {
const response = JSON.parse(body).result
if (error) return
if (!response) return
this.id = response.id || ''
this.first_name = response.first_name || ''
this.last_name = response.last_name || ''
this.username = response.username || ''
this.language_code = response.language_code || ''
resolve()
})
})
}
getName() {
if (this.last_name) {
return `${this.first_name} ${this.last_name}`
}
else {
return `${this.first_name}`
}
}
introduceYourself() {
console.log(`Hello, my name is ${this.getName()}. You can talk to me through my username: @${this.username}`);
}
}