BotSharp/src/Plugins/BotSharp.Plugin.WebDriver/Functions/OpenBrowserFn.cs

27 lines
852 B
C#
Raw Normal View History

2024-01-03 19:40:41 +00:00
using BotSharp.Plugin.WebDriver.Drivers.PlaywrightDriver;
2024-01-03 04:43:37 +00:00
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);
2024-01-23 23:14:57 +00:00
message.Content = string.IsNullOrEmpty(args.Url) ? $"Launch browser with blank page successfully." : $"Open website {args.Url} successfully.";
2024-01-03 04:43:37 +00:00
return true;
}
}