BotSharp/src/Plugins/BotSharp.Plugin.WebDriver/Functions/OpenBrowserFn.cs
2024-01-23 17:14:57 -06:00

27 lines
852 B
C#

using BotSharp.Plugin.WebDriver.Drivers.PlaywrightDriver;
namespace BotSharp.Plugin.WebDriver.Functions;
public class OpenBrowserFn : IFunctionCallback
{
public string Name => "open_browser";
private readonly IServiceProvider _services;
private readonly PlaywrightWebDriver _driver;
public OpenBrowserFn(IServiceProvider services,
PlaywrightWebDriver driver)
{
_services = services;
_driver = driver;
}
public async Task<bool> Execute(RoleDialogModel message)
{
var args = JsonSerializer.Deserialize<BrowsingContextIn>(message.FunctionArgs);
var browser = await _driver.LaunchBrowser(args.Url);
message.Content = string.IsNullOrEmpty(args.Url) ? $"Launch browser with blank page successfully." : $"Open website {args.Url} successfully.";
return true;
}
}