File size: 1,252 Bytes
35ee763
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { TelegramClient } from 'telegram'
import { StringSession } from 'telegram/sessions'
import { notification } from 'antd'

export const telegramClient = {
  connect: async (session = localStorage.getItem('session')): Promise<TelegramClient> => {
    if (session === null || session === undefined) {
      notification.info({ message: 'Experimental feature', description: 'Join the experimental features in the Settings page' })
      throw { status: 401, message: 'Session not found' }
    }
    const client = new TelegramClient(new StringSession(session), Number(process.env.REACT_APP_TG_API_ID), process.env.REACT_APP_TG_API_HASH as string, {
      connectionRetries: 10,
      useWSS: true,
      // baseLogger: new Logger(LogLevel.NONE)
    })
    await client.connect()
    return client
  }
}

export const anonymousTelegramClient = {
  connect: async (session = localStorage.getItem('session') || ''): Promise<TelegramClient> => {
    const client = new TelegramClient(new StringSession(session), Number(process.env.REACT_APP_TG_API_ID), process.env.REACT_APP_TG_API_HASH as string, {
      connectionRetries: 10,
      useWSS: true,
      // baseLogger: new Logger(LogLevel.NONE)
    })
    await client.connect()
    return client
  }
}