BotSharp/src/Infrastructure/BotSharp.Core.Crontab/Functions/ScheduleTaskFn.cs

38 lines
1.1 KiB
C#
Raw Normal View History

2024-12-05 17:11:16 +00:00
using BotSharp.Abstraction.Routing;
using BotSharp.Abstraction.Users;
2024-12-06 15:49:34 +00:00
using BotSharp.Core.Crontab.Hooks;
2024-12-05 17:11:16 +00:00
namespace BotSharp.Core.Crontab.Functions;
public class ScheduleTaskFn : IFunctionCallback
{
2024-12-06 15:49:34 +00:00
public string Name => $"{CrontabUtilityHook.PREFIX}schedule_task";
2024-12-05 17:11:16 +00:00
private readonly IServiceProvider _services;
public ScheduleTaskFn(IServiceProvider services)
{
_services = services;
}
public async Task<bool> Execute(RoleDialogModel message)
{
var args = JsonSerializer.Deserialize<ScheduleTaskArgs>(message.FunctionArgs);
var routing = _services.GetRequiredService<IRoutingContext>();
var user = _services.GetRequiredService<IUserIdentity>();
var crontabItem = new CrontabItem
{
Topic = args.Topic,
Description = args.Description,
Cron = args.Cron,
Script = args.Script,
Language = args.Language,
UserId = user.Id,
AgentId = routing.EntryAgentId,
ConversationId = routing.ConversationId
};
return true;
}
}