ReplaceToken

This commit is contained in:
Haiping Chen 2024-02-10 11:36:43 -06:00
parent a5f8536211
commit 71e17741b5
3 changed files with 27 additions and 2 deletions

View file

@ -16,6 +16,9 @@ public partial class PlaywrightWebDriver
if (!string.IsNullOrEmpty(url))
{
var webDriverService = _services.GetRequiredService<WebDriverService>();
url = webDriverService.ReplaceToken(url);
var response = await page.GotoAsync(url, new PageGotoOptions
{
Timeout = 15 * 1000

View file

@ -1,5 +1,3 @@
using BotSharp.Plugin.WebDriver.LlmContexts;
namespace BotSharp.Plugin.WebDriver.Services;
public partial class WebDriverService

View file

@ -0,0 +1,24 @@
using System.Text.RegularExpressions;
namespace BotSharp.Plugin.WebDriver.Services;
public partial class WebDriverService
{
/// <summary>
/// Replace token started @ with settings.
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public string ReplaceToken(string text)
{
var config = _services.GetRequiredService<IConfiguration>();
var token = Regex.Match(text, "@[a-zA-Z0-9._]+");
if (token.Success)
{
var key = token.Value.Replace("@", "").Replace(".", ":");
var value = config.GetValue<string>(key);
return text.Replace(token.Value, value);
}
return text;
}
}