UNPKG

1.85 kBJavaScriptView Raw
1const test = require('tap').test
2const { ApiManager } = require('../lib/index')
3
4const phone = {
5 num : '+9996620000',
6 code: '22222'
7}
8
9const 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}
17const server = {
18 dev : true,
19 webogram: true
20}
21const debug = true
22
23const config = {
24 // NOTE: if you FORK the project you MUST use your APP ID.
25 // Otherwise YOUR APPLICATION WILL BE BLOCKED BY TELEGRAM
26 // You can obtain your own APP ID for your application here: https://my.telegram.org
27 id : 49631,
28 hash: 'fb050b8f6771e15bfda5df2409931569'
29}
30
31
32const telegramMain = new ApiManager({ server, api, app: { debug } })
33
34test(`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