Skip to content

Commit

Permalink
Custom bot api server configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
voed committed Oct 31, 2023
1 parent 9e14fb7 commit 6b2bb59
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
11 changes: 8 additions & 3 deletions TGBotFramework/BotFramework/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Bot: IHostedService, IBotInstance
private TelegramBotClient client;

private EventHandlerFactory factory;

public Bot(IServiceProvider services, IServiceScopeFactory scopeFactory, Type startupType = null)
{
this.services = services;
Expand Down Expand Up @@ -64,18 +64,23 @@ private async Task StartListen(CancellationToken cancellationToken)

try
{
var apiUrl = _config.BotApiUrl;
if(string.IsNullOrWhiteSpace(apiUrl))
apiUrl = null;
var options = new TelegramBotClientOptions(_config.Token, apiUrl, _config.UseTestEnv);

if(_config.UseSOCKS5)
{
var proxy = new HttpToSocks5Proxy(_config.SOCKS5Address, _config.SOCKS5Port, _config.SOCKS5User,
_config.SOCKS5Password);
var handler = new HttpClientHandler { Proxy = proxy };
var httpClient = new HttpClient(handler, true);

client = new TelegramBotClient(_config.Token, httpClient);
client = new TelegramBotClient(options, httpClient);
}
else
{
client = new TelegramBotClient(_config.Token);
client = new TelegramBotClient(options);
}

factory = new EventHandlerFactory();
Expand Down
2 changes: 2 additions & 0 deletions TGBotFramework/BotFramework/Config/BotConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public class BotConfig
public string SOCKS5User { get; set; }
public string SOCKS5Password { get; set; }
public bool UseSOCKS5 { get; set; }
public bool UseTestEnv { get; set; }
public string BotApiUrl { get; set; }
}
}
4 changes: 3 additions & 1 deletion TGBotFramework/BotFramework/Config/DefaultConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
"sockS5Port": null,
"sockS5User": null,
"sockS5Password": null,
"useSOCKS5": false
"useSOCKS5": false,
"useTestEnv": false,
"botApiUrl": null
}

0 comments on commit 6b2bb59

Please sign in to comment.