Skip to content

Commit cbf4589

Browse files
authored
Custom bot api server configuration (#177)
1 parent 9e14fb7 commit cbf4589

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

TGBotFramework/BotFramework/Bot.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class Bot: IHostedService, IBotInstance
3232
private TelegramBotClient client;
3333

3434
private EventHandlerFactory factory;
35-
35+
3636
public Bot(IServiceProvider services, IServiceScopeFactory scopeFactory, Type startupType = null)
3737
{
3838
this.services = services;
@@ -64,18 +64,23 @@ private async Task StartListen(CancellationToken cancellationToken)
6464

6565
try
6666
{
67+
var apiUrl = _config.BotApiUrl;
68+
if(string.IsNullOrWhiteSpace(apiUrl))
69+
apiUrl = null;
70+
var options = new TelegramBotClientOptions(_config.Token, apiUrl, _config.UseTestEnv);
71+
6772
if(_config.UseSOCKS5)
6873
{
6974
var proxy = new HttpToSocks5Proxy(_config.SOCKS5Address, _config.SOCKS5Port, _config.SOCKS5User,
7075
_config.SOCKS5Password);
7176
var handler = new HttpClientHandler { Proxy = proxy };
7277
var httpClient = new HttpClient(handler, true);
7378

74-
client = new TelegramBotClient(_config.Token, httpClient);
79+
client = new TelegramBotClient(options, httpClient);
7580
}
7681
else
7782
{
78-
client = new TelegramBotClient(_config.Token);
83+
client = new TelegramBotClient(options);
7984
}
8085

8186
factory = new EventHandlerFactory();

TGBotFramework/BotFramework/Config/BotConfig.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ public class BotConfig
1212
public string SOCKS5User { get; set; }
1313
public string SOCKS5Password { get; set; }
1414
public bool UseSOCKS5 { get; set; }
15+
public bool UseTestEnv { get; set; }
16+
public string BotApiUrl { get; set; }
1517
}
1618
}

TGBotFramework/BotFramework/Config/DefaultConfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@
88
"sockS5Port": null,
99
"sockS5User": null,
1010
"sockS5Password": null,
11-
"useSOCKS5": false
11+
"useSOCKS5": false,
12+
"useTestEnv": false,
13+
"botApiUrl": null
1214
}

0 commit comments

Comments
 (0)