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

29 lines
929 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-06 03:24:13 +00:00
message.Content = string.IsNullOrEmpty(args.Url) ? "Launch browser successfully." : $"Open website successfully.";
message.Content += "\r\nWhat would you like to do next?";
message.StopCompletion = true;
2024-01-03 04:43:37 +00:00
return true;
}
}