public async Task <IActionResult> Create([Bind("ChannelId,ChannelUserName,HasContainFilter,IntervalMins")] TelegramChannel telegramChannel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    TelegramCollector.mustwait      = true;
                    TelegramCollector.mustwaittilme = 15000;
                    Thread.Sleep(5000);
                    var channel = TelegramClientManager.GetTChannelbyUsername(telegramChannel.ChannelUserName);
                    if (channel == null)
                    {
                        return(RedirectToAction(nameof(Index)));
                    }
                    Thread.Sleep(8000);
                    NewsConcentratorSystem.NewsScraper.TelegramClientManager
                    .JoinChannel(telegramChannel.ChannelUserName)
                    .Wait();
                    //Insert Entity in DB
                    telegramChannel.ChannelChatID   = channel.Id.ToString();
                    telegramChannel.AccessHash      = channel.AccessHash.ToString();
                    telegramChannel.ChannelUserName = channel.Username;
                    telegramChannel.ChannelTitle    = channel.Title;
                    _context.Add(telegramChannel);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return(NotFound());
                }
            }
            return(View(telegramChannel));
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            #region TelegramClientConfiguraition



            int    app_id   = 4290367;
            string api_hash = "4bf7b77ff1072c71f94e3ff4a883777a";
            var    store    = new FileSessionStore();



            Console.WriteLine("Choose authentication method:\n");
            Console.WriteLine("1) Login by phone number authentication");
            Console.WriteLine("2) Store last session file");



            var cki = Console.ReadKey();
            if (cki.KeyChar == '2')
            {
                try
                {
                    client = new TelegramClient(app_id, api_hash, store);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    Environment.Exit(-1);
                }
                TelegramClientManager._client = client;
            }

            else if (cki.KeyChar == '1')
            {
                TelegramClientManager.CreateClientbyAuthorize(app_id, api_hash).Wait();
                client = TelegramClientManager._client;
            }



            while (true)
            {
                try
                {
                    //send message
                    client.ConnectAsync(false).Wait();
                    break;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    Console.WriteLine("/n /n any key to retying...");
                    Console.ReadKey();
                    //countinue
                }
            }

            keepconnected_timer.Enabled = false;

            //var client = new TelegramClient(app_id,api_hash);

            //Console.Write("Enter numberphone:");
            //var numberphone = Console.ReadLine();

            //var hash = await client.SendCodeRequestAsync(numberphone);
            Console.WriteLine("Is connected: " + client.IsConnected);
            Console.WriteLine("Is user authorized: " + client.IsUserAuthorized());

            collector = new TelegramCollector();
            // Console.Write("Enter Verifacation code:");


            #endregion

            //    Console.WriteLine("hellop hellop wordpppp");
            CreateHostBuilder(args).Build().Run();
        }