A self-contained Laravel package that enables time-based agent execution for PromptlyAgent using Laravel's scheduling system.
- β° Multiple Schedule Types: One-time, recurring (hourly/daily/weekly/monthly), custom intervals, and cron expressions
- π Automatic Execution: Integrated with Laravel scheduler for reliable execution
- π Placeholder Support: Dynamic placeholders for dates, times, and custom variables
- π Timezone-Aware: Full timezone support for accurate scheduling across regions
- π― Manual Execution: UI button for immediate trigger testing
- π Execution Tracking: Built-in statistics and logging
- π Queue Integration: Async execution via Laravel Horizon/Queue
Configure time-based triggers through the PromptlyAgent admin interface:
Schedule type selection, timezone settings, and recurrence configuration
Placeholder support, execution history, and manual trigger controls
The package is auto-discovered by Laravel and requires no manual setup beyond:
-
Ensure Laravel Scheduler is Running:
# The scheduler is configured in docker/supervisor/supervisord.conf # Runs: php artisan schedule:work
-
Verify Package is Loaded:
php artisan schedule:list # Should show registered scheduled triggers
packages/schedule-trigger/
βββ src/
β βββ Commands/
β β βββ ExecuteScheduledTriggerCommand.php # CLI execution
β βββ Http/Controllers/
β β βββ ScheduledTriggerController.php # Manual execution endpoint
β βββ Jobs/
β β βββ ExecuteScheduledTriggerJob.php # Async queue job
β βββ Providers/
β β βββ ScheduledInputTriggerProvider.php # Main trigger provider
β βββ Services/
β β βββ ScheduleManager.php # Laravel scheduler integration
β β βββ ScheduleCalculator.php # Next run calculations
β β βββ PlaceholderResolver.php # Dynamic placeholder engine
β β βββ HttpDataFetcher.php # External data fetching
β βββ Support/
β β βββ ScheduleConfig.php # Config value object
β βββ ScheduleIntegrationServiceProvider.php # Package bootstrap
βββ resources/views/
β βββ trigger-config.blade.php # UI configuration form
βββ composer.json
tests/Feature/
βββ ScheduledTriggerIntegrationTest.php # Integration tests
-
Service Provider Registration:
- Registers all services as singletons
- Registers routes for manual execution
- Registers commands
- Hooks into Laravel's Schedule resolver using
callAfterResolving() - Registers provider with InputTriggerRegistry and ProviderRegistry
-
Schedule Registration:
ScheduleManagerloads active scheduled triggers from database- Converts trigger config to Laravel schedule definitions
- Caches for 5 minutes for performance
- Cache invalidates on trigger save/delete
-
Execution Flow:
- Laravel scheduler runs
schedule:work(via supervisor) - At scheduled time, executes
scheduled-trigger:execute {trigger_id} - Command resolves placeholders and invokes
TriggerExecutor TriggerExecutorcreates chat session and executes agent- Results appear in user's chat interface
- Laravel scheduler runs
-
Manual Execution:
- UI button dispatches
ExecuteScheduledTriggerJobto queue - Job resolves placeholders and executes trigger asynchronously
- User gets immediate feedback without waiting for agent completion
- UI button dispatches
Triggers store configuration in input_triggers.config JSON column:
{
"schedule_type": "recurring",
"timezone": "UTC",
"recurring": {
"type": "daily",
"time": "09:00",
"days_of_week": [1, 2, 3, 4, 5]
},
"input_text": "Analyze today's metrics for {{date}}",
"placeholders": {
"static": {
"company": "Acme Corp"
}
},
"execution_limits": {
"max_executions": 100,
"expires_at": "2025-12-31T23:59:59"
},
"error_handling": {
"on_failure": "continue",
"max_consecutive_failures": 3
}
}All placeholders are timezone-aware and resolved at execution time:
{{date}}- Current date (Y-m-d){{time}}- Current time (H:i:s){{datetime}}- Current date and time{{timestamp}}- Unix timestamp{{day}}- Day of week (Monday-Sunday){{week}}- Week number{{month}}- Month name{{year}}- Four-digit year{{trigger_id}}- Trigger UUID{{trigger_name}}- Trigger name{{user_id}}- Trigger owner's user ID{{execution_count}}- Total executions so far
Via UI: Navigate to Integrations β Create Trigger β Select "Scheduled Trigger"
Via Code:
use App\Models\InputTrigger;
$trigger = InputTrigger::create([
'user_id' => auth()->id(),
'provider_id' => 'schedule',
'name' => 'Daily Report',
'agent_id' => $agent->id,
'session_strategy' => 'new_each',
'status' => 'active',
'config' => [
'schedule_type' => 'recurring',
'timezone' => 'UTC',
'input_text' => 'Generate daily report for {{date}}',
'recurring' => [
'type' => 'daily',
'time' => '09:00',
],
'error_handling' => [
'on_failure' => 'continue',
'max_consecutive_failures' => 3,
],
],
]);# Via CLI
php artisan scheduled-trigger:execute {trigger-id}
# Via HTTP (authenticated)
POST /integrations/triggers/{trigger-id}/executeRun the integration test suite:
php artisan test --filter=ScheduledTriggerIntegrationTestTests cover:
- Provider registration
- Creating all schedule types
- Updating triggers
- Validation rules
- Static placeholders
- Execution limits
- HTTP security bypass
The package requires minimal core app integration:
-
Composer Registration (
composer.json):{ "require": { "promptlyagentai/schedule-trigger": "@dev" }, "repositories": [ { "type": "vcs", "url": "https://github.com/promptlyagentai/schedule-trigger.git" } ] } -
Scheduler Running (
docker/supervisor/supervisord.conf):[program:scheduler] command=/usr/bin/php /var/www/html/artisan schedule:work autostart=true autorestart=true
-
UI Integration (
resources/views/settings/integrations/trigger-details.blade.php):- Execute Now button for scheduled triggers
-
Integration Test (
tests/Feature/ScheduledTriggerIntegrationTest.php):- Comprehensive test coverage
- Laravel 12+
- PHP 8.2+
- Laravel Queue/Horizon (for async execution)
- Cron Expression Parser (
dragonmantank/cron-expression)
- No HTTP endpoints exposed (internal scheduler only)
- No rate limits or IP whitelisting required
- User authentication enforced on manual execution endpoint
- All execution logged with user context
- Schedule cache: 5 minutes TTL
- Singleton services for minimal overhead
- Lazy loading of triggers
- Async execution via queue prevents blocking
- Check scheduler is running:
supervisorctl status scheduler - Verify trigger is active: Check
input_triggers.status = 'active' - Check logs:
storage/logs/laravel.logfor schedule registration - View schedule:
php artisan schedule:list
- Verify queue worker is running (Horizon)
- Check job failed logs: Horizon dashboard
- Review
storage/logs/laravel.logfor job errors
- Check placeholder syntax: Must use
{{placeholder}} - Verify timezone configuration
- Review placeholder resolver logs
MIT License. See LICENSE for details.
For issues and questions, please use this repository: https://github.com/promptlyagentai/schedule-trigger

