2024-01-03 04:43:37 +00:00
|
|
|
namespace BotSharp.Plugin.WebDriver.Functions;
|
|
|
|
|
|
2024-01-06 03:24:13 +00:00
|
|
|
public class InputUserPasswordFn : IFunctionCallback
|
2024-01-03 04:43:37 +00:00
|
|
|
{
|
2024-01-06 03:24:13 +00:00
|
|
|
public string Name => "input_user_password";
|
2024-01-03 04:43:37 +00:00
|
|
|
|
|
|
|
|
private readonly IServiceProvider _services;
|
2024-02-06 05:05:52 +00:00
|
|
|
private readonly IWebBrowser _browser;
|
2024-01-03 04:43:37 +00:00
|
|
|
|
2024-01-06 03:24:13 +00:00
|
|
|
public InputUserPasswordFn(IServiceProvider services,
|
2024-02-06 05:05:52 +00:00
|
|
|
IWebBrowser browser)
|
2024-01-03 04:43:37 +00:00
|
|
|
{
|
|
|
|
|
_services = services;
|
2024-02-06 05:05:52 +00:00
|
|
|
_browser = browser;
|
2024-01-03 04:43:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<bool> Execute(RoleDialogModel message)
|
|
|
|
|
{
|
|
|
|
|
var args = JsonSerializer.Deserialize<BrowsingContextIn>(message.FunctionArgs);
|
|
|
|
|
|
|
|
|
|
var agentService = _services.GetRequiredService<IAgentService>();
|
|
|
|
|
var agent = await agentService.LoadAgent(message.CurrentAgentId);
|
2024-02-06 05:05:52 +00:00
|
|
|
var result = await _browser.InputUserPassword(new BrowserActionParams(agent, args, message.MessageId));
|
|
|
|
|
|
2024-02-08 21:39:56 +00:00
|
|
|
message.Content = result ? "Input password successfully" : "Input password failed";
|
2024-01-03 04:43:37 +00:00
|
|
|
|
2024-02-06 14:07:09 +00:00
|
|
|
var webDriverService = _services.GetRequiredService<WebDriverService>();
|
2024-02-06 20:42:35 +00:00
|
|
|
var path = webDriverService.GetScreenshotFilePath(message.MessageId);
|
2024-02-06 14:07:09 +00:00
|
|
|
|
|
|
|
|
message.Data = await _browser.ScreenshotAsync(path);
|
|
|
|
|
|
2024-01-03 04:43:37 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|