-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
56 lines (51 loc) · 1.84 KB
/
cli.js
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
49
50
51
52
53
54
55
56
#!/usr/bin/env node
const _ = require("lodash")
const input = require("input")
const dotenv = require("dotenv")
const { Api, startSession, eventEmitter } = require("./dist/index.cjs")
dotenv.config()
/**
* Setting fallback API_ID and API_HASH from public data on github
* https://github.com/zhukov/webogram/blob/master/app/js/lib/config.js
*/
const API_ID = _.toNumber(process.env.API_ID || 2496)
const API_HASH = _.toString(process.env.API_HASH || "8da85b0d5bfe62527e5b244c209159c3")
eventEmitter
.on("RequiresPhoneNumber", (phoneNumberEmitter) => {
input.text("Enter phone number :").then((phoneNumber) => {
phoneNumberEmitter(phoneNumber)
})
})
.on("RequiresPhoneCode", (phoneCodeEmitter) => {
input.text("Enter phone code :").then((phoneCode) => {
phoneCodeEmitter(phoneCode)
})
})
.on("RequiresPassword", (passwordEmitter) => {
input.password("Enter password :").then((password) => {
passwordEmitter(password)
})
})
.on("RequiresFirstAndLastNames", async (firstAndLastNamesEmitter) => {
const firstName = await input.text("Enter first name :")
const lastName = await input.text("Enter last name :")
firstAndLastNamesEmitter(firstName, lastName)
})
startSession({ apiId: API_ID, apiHash: API_HASH })
.then((client) => {
return client.invoke(new Api.users.GetUsers({ id: [new Api.InputUserSelf()] }))
})
.then(([{ firstName }]) => {
console.log("🖐️ Hi", firstName)
console.log("Currently, you are listening to 'UpdateShortMessage' events ...")
})
.then(() => {
eventEmitter.on("UpdateShortMessage", (event) => {
console.log(event)
})
})
.catch(({ message }) => {
if (!_.includes(message, "400")) {
process.exit(1)
}
})