1 | const telegram = require('./init')
|
2 |
|
3 | const { inputField } = require('./fixtures')
|
4 |
|
5 | const config = {
|
6 |
|
7 |
|
8 |
|
9 | id : 49631,
|
10 | hash: 'fb050b8f6771e15bfda5df2409931569'
|
11 | }
|
12 |
|
13 | const login = async () => {
|
14 | try {
|
15 | const phone = await inputField('phone')
|
16 | console.log(phone)
|
17 | await telegram('help.getNearestDc', {},
|
18 | { dcID: 2, createNetworker: true })
|
19 | const { phone_code_hash } = await telegram('auth.sendCode', {
|
20 | phone_number : phone,
|
21 | current_number: false,
|
22 | api_id : config.id,
|
23 | api_hash : config.hash
|
24 | })
|
25 | const code = await inputField('code')
|
26 | const res = await telegram('auth.signIn', {
|
27 | phone_number: phone,
|
28 | phone_code_hash,
|
29 | phone_code : code
|
30 | })
|
31 | const { user } = res
|
32 | const {
|
33 | first_name = '',
|
34 | username = ''
|
35 | } = user
|
36 | console.log('signIn', first_name, username, user.phone)
|
37 | return telegram
|
38 | } catch (error) {
|
39 | console.error(error)
|
40 | }
|
41 | }
|
42 |
|
43 | module.exports = login |
\ | No newline at end of file |