1 | const test = require('tap').test
|
2 | const { ApiManager } = require('../lib/index')
|
3 |
|
4 | const phone = {
|
5 | num : '+9996620000',
|
6 | code: '22222'
|
7 | }
|
8 |
|
9 | const api = {
|
10 | invokeWithLayer: 0xda9b0d0d,
|
11 | layer : 57,
|
12 | initConnection : 0x69796de9,
|
13 | api_id : 49631,
|
14 | app_version : '1.0.1',
|
15 | lang_code : 'en'
|
16 | }
|
17 | const server = {
|
18 | dev : true,
|
19 | webogram: true
|
20 | }
|
21 | const debug = true
|
22 |
|
23 | const config = {
|
24 |
|
25 |
|
26 |
|
27 | id : 49631,
|
28 | hash: 'fb050b8f6771e15bfda5df2409931569'
|
29 | }
|
30 |
|
31 |
|
32 | const telegramMain = new ApiManager({ server, api, app: { debug } })
|
33 |
|
34 | test(`Connection test`, async t => {
|
35 | t.plan(1)
|
36 | const run = async () => {
|
37 | let res, i = 0
|
38 | while (i<5) {
|
39 | try {
|
40 | res = await telegramMain.mtpInvokeApi('help.getNearestDc', {}, { dcID: 2, createNetworker: true })
|
41 | console.log('getNearestDc', res)
|
42 | const { phone_code_hash } = await telegramMain.mtpInvokeApi('auth.sendCode', {
|
43 | phone_number : phone.num,
|
44 | current_number: false,
|
45 | api_id : config.id,
|
46 | api_hash : config.hash
|
47 | })
|
48 | console.log('phone_code_hash', phone_code_hash)
|
49 | res = await telegramMain.mtpInvokeApi('auth.signIn', {
|
50 | phone_number: phone.num,
|
51 | phone_code_hash,
|
52 | phone_code : phone.code
|
53 | })
|
54 | console.log('signIn', res)
|
55 | console.log('\n Logined as user')
|
56 | console.dir(res.user, { colors: true })
|
57 | t.ok(res, 'result is ok')
|
58 | break
|
59 | } catch (err) {
|
60 | console.log('err', res)
|
61 | }
|
62 | i++
|
63 | }
|
64 | }
|
65 | await run()
|
66 | }) |
\ | No newline at end of file |