UNPKG

1.24 kBJavaScriptView Raw
1const telegram = require('./init')
2
3const { inputField } = require('./fixtures')
4
5const config = {
6 // NOTE: if you FORK the project you MUST use your APP ID.
7 // Otherwise YOUR APPLICATION WILL BE BLOCKED BY TELEGRAM
8 // You can obtain your own APP ID for your application here: https://my.telegram.org
9 id : 49631,
10 hash: 'fb050b8f6771e15bfda5df2409931569'
11}
12
13const 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
43module.exports = login
\No newline at end of file