/// <summary>
        /// Start ngrok server and fetch the assigned ngrok url
        /// </summary>
        /// <returns></returns>
        private static async Task <string> StartNgrokService()
        {
            try
            {
                var ngrokPath = ConfigurationManager.AppSettings["NgrokExePath"];

                if (string.IsNullOrEmpty(ngrokPath))
                {
                    Logger.LogMessage(Logger.MessageType.INFORMATION, "Ngrok path not provided");
                    return(null);
                }

                Logger.LogMessage(Logger.MessageType.INFORMATION, "Starting Ngrok");
                ngrokService = new NgrokService(ngrokPath);

                Logger.LogMessage(Logger.MessageType.INFORMATION, "Fetching Ngrok Url");
                var ngrokUrl = await ngrokService.GetNgrokUrl();

                Logger.LogMessage(Logger.MessageType.INFORMATION, $"Ngrok Started with url: {ngrokUrl}");

                return(ngrokUrl);
            }
            catch (Exception ex)
            {
                Logger.LogMessage(Logger.MessageType.ERROR, ex.Message);
                return(null);
            }
        }
コード例 #2
0
        public BotController(IOptions <TelegramOptions> tgOptions, IOptions <ProxyOptions> proxyOptions, IOptions <NgrokOptions> ngrokOptions)
        {
            _ngrokService = new NgrokService(ngrokOptions.Value.LocalUrl);
            _tgOptions    = tgOptions.Value;
            _proxyOptions = proxyOptions.Value;
            var proxy = new HttpToSocks5Proxy(_proxyOptions.Host, _proxyOptions.Port, _proxyOptions.User, _proxyOptions.Password);

            proxy.ResolveHostnamesLocally = true;
            _client = new TelegramBotClient(_tgOptions.Token, proxy);
        }