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

33 lines
1 KiB
C#
Raw Normal View History

2024-01-03 04:43:37 +00:00
using BotSharp.Abstraction.Agents;
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;
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;
private readonly PlaywrightWebDriver _driver;
2024-01-06 03:24:13 +00:00
public InputUserPasswordFn(IServiceProvider services,
2024-01-03 04:43:37 +00:00
PlaywrightWebDriver driver)
{
_services = services;
_driver = driver;
}
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-01-23 23:14:57 +00:00
await _driver.Instance.Page.WaitForLoadStateAsync(LoadState.Load);
2024-01-06 03:24:13 +00:00
await _driver.InputUserPassword(agent, args, message.MessageId);
2024-01-03 04:43:37 +00:00
2024-01-06 03:24:13 +00:00
message.Content = "Input password successfully";
2024-01-03 04:43:37 +00:00
return true;
}
}