Example #1
0
        public TelegramUserModel IsUserAuth()
        {
            if (Properties.Socials.Default.TelegramUserID != 0)
            {
                try
                {
                    var loadedSession = store.Load("session");
                    session = Session.TryLoadOrCreateNew(store, Properties.Socials.Default.TelegramUserID.ToString());

                    var ph = imghlp.byteArrayToImage(loadedSession.TLUser.Photo.Serialize());
                    TelegramUserModel telegramuser = (new TelegramUserModel
                    {
                        UserID = loadedSession.TLUser.Id.ToString(),
                        UserNameAndSurname = loadedSession.TLUser.FirstName + " " + loadedSession.TLUser.LastName,
                        UserNickName = loadedSession.TLUser.Username,
                        UserPhoto = ph
                    });
                    return(telegramuser);
                }
                catch { return(null); }
            }
            else
            {
                return(null);
            }
        }
Example #2
0
        public static TelegramClient NewClient()
        {
            try
            {
                String path_sess   = Values.SessionsPath + "\\" + Values.apiID + "_" + Values.apiPhone + "\\" + Values.apiPhone.Replace(" + ", "");
                string sessionPath = Path.Combine(Application.StartupPath, path_sess);
                Store.Load(sessionPath);

                return(new TelegramClient(Values.apiID, Values.apiHash, Store, sessionPath, handler: _connect));
            }
            catch (MissingApiConfigurationException ex)
            {
                throw new Exception($"Missing app.config file",
                                    ex);
            }
            catch (SocketException ex)
            {
                throw new Exception($"Dont can connect", ex);
            }
        }