A comprehensive AI-powered chat widget for Moodle 4.5+ that provides context-aware tutoring, support, and study planning for students.
Release Date: January 2025 Requires: Moodle 4.5+ (2024100700) License: GPL v3+
- Floating Chat Widget: Non-intrusive, always-available AI tutor on course pages
- Context-Aware: Ingests course structure to provide relevant, course-specific guidance
- Streaming Responses: Real-time SSE (Server-Sent Events) for responsive user experience
- Multi-Provider Support: Claude, OpenAI, Ollama, MiniMax, custom OpenAI-compatible APIs
- Role-Based Behavior: Adapts responses for students, academic support staff, and administrators
- Socratic Tutoring: Guides students to answers rather than giving direct solutions
- FAQ Support: Centralized knowledge base for common questions
- Study Planning: Personalized study schedules based on available hours per week
- Reminders: Opt-in email/WhatsApp study reminders with country restrictions
- AI Literacy: Teaches students how to use AI effectively
- Multilingual: Auto-detects and responds in 100+ languages
- Conversation Persistence: Continues conversations where students left off
- Audio Playback: Listen to AI responses using Text-to-Speech
- Copy Conversations: Export chat history to clipboard
- Data Management: Self-service data deletion from user settings
- Analytics Dashboard: Monitor student engagement and trends
- Course Hotspots: Identify sections where students struggle
- Common Prompts: See frequently asked questions
- Usage Statistics: Track adoption and activity
- Off-Topic Detection: Automatic identification of non-course-related conversations
- Comprehensive Settings: Fine-tune behavior, limits, and integrations
- Off-Topic Management: Configure limits and lockout duration
- Provider Configuration: Choose and configure AI provider
- Zendesk Integration: Auto-escalate unresolved issues to support tickets
- Audit Logging: Full SOC2-compliant audit trail
- Rate Limiting: Protect against abuse and API cost overruns
- SOC2 Compliant: Audit logging, encryption, access controls
- GDPR Ready: Full Privacy API implementation
- Encrypted API Keys: Secure credential storage
- Rate Limiting: User and IP-based throttling
- Input Validation: XSS and SQL injection protection
- Session Security: Moodle-integrated authentication
- Download or clone this repository
- Extract to
{moodle_root}/local/ai_course_assistant/ - Visit Site Administration → Notifications to complete installation
- Configure settings at Site Administration → Plugins → Local plugins → AI Course Assistant
- Enable Plugin: Turn on the AI Course Assistant
- AI Provider: Choose your provider (Claude, OpenAI, etc.)
- API Key: Enter your provider's API key (stored encrypted)
- Model: Select the model (e.g., claude-sonnet-4, gpt-4o)
- System Prompt: Customize the AI's personality and behavior
- Max History: Limit conversation context (default: 20 message pairs)
- Avatar: Choose from 10 included avatars
- Position: Bottom-right or bottom-left
- FAQ: Add common questions and answers
- Zendesk: Configure for automatic ticket creation
- Study Reminders: Enable email/WhatsApp notifications
- Off-Topic Detection: Set limits and actions
- Open any course page
- Click the floating avatar button (bottom-right by default)
- Start asking questions about the course
- Use Shift+Enter for new lines, Enter to send
- Click copy button to export conversation
- Click play button on AI messages to hear them aloud
- Visit your user settings to manage your data
- Access analytics dashboard from chat widget header (if enabled)
- Review student engagement trends
- Identify course content hotspots needing clarification
- See common prompt patterns
- Configure plugin settings at Site Administration
- Set off-topic limits and lockout duration
- Review audit logs for security and usage
- Monitor API costs and usage patterns
- AMD Modules: Modern JavaScript with ES6+ features
- SSE Client: Efficient streaming with ReadableStream API
- Markdown Rendering: Lightweight, secure markdown parser
- Audio Player: Web Speech API for TTS (no external dependencies)
- Responsive Design: Mobile-first CSS with breakpoints
- Provider Layer: Interface → Base → Specific implementations
- Context Builder: Course structure ingestion with caching
- Conversation Manager: Message persistence and history management
- Rate Limiter: Sliding window algorithm with caching
- Audit Logger: SOC2-compliant activity tracking
- 4 Main Tables:
local_ai_course_assistant_convs: Conversationslocal_ai_course_assistant_msgs: Messageslocal_ai_course_assistant_plans: Study planslocal_ai_course_assistant_reminders: Reminder subscriptionslocal_ai_course_assistant_audit: Security audit log
- System Prompts: 1 hour TTL, invalidates on course changes
- Rate Limits: 2 minutes TTL, sliding window tracking
ai_course_assistant/
├── version.php # Plugin metadata
├── settings.php # Admin settings page
├── settings_user.php # Student data management page
├── analytics.php # Analytics dashboard
├── unsubscribe.php # Reminder opt-out page
├── sse.php # SSE streaming endpoint
├── lib.php # Legacy compatibility
├── README.md # This file
├── SECURITY.md # Security documentation
├── db/
│ ├── install.xml # Database schema
│ ├── upgrade.php # Upgrade scripts
│ ├── access.php # Capability definitions
│ ├── hooks.php # Hook registrations
│ ├── services.php # External function definitions
│ ├── tasks.php # Scheduled tasks
│ ├── messages.php # Message providers
│ └── caches.php # Cache definitions
├── lang/en/
│ └── local_ai_course_assistant.php # Language strings
├── classes/
│ ├── hook_callbacks.php # Widget injection
│ ├── conversation_manager.php # Message CRUD
│ ├── context_builder.php # System prompt builder
│ ├── faq_manager.php # FAQ parsing
│ ├── zendesk_client.php # Zendesk API
│ ├── study_planner.php # Study plan management
│ ├── reminder_manager.php # Reminder delivery
│ ├── analytics.php # Usage analytics
│ ├── rate_limiter.php # Rate limiting
│ ├── audit_logger.php # Audit logging
│ ├── provider/
│ │ ├── provider_interface.php
│ │ ├── base_provider.php
│ │ ├── claude_provider.php
│ │ ├── openai_compatible_provider.php
│ │ ├── openai_provider.php
│ │ ├── ollama_provider.php
│ │ ├── minimax_provider.php
│ │ └── custom_provider.php
│ ├── external/ # External API functions
│ ├── task/
│ │ └── send_reminders.php
│ └── privacy/
│ └── provider.php # GDPR implementation
├── templates/
│ ├── chat_widget.mustache # Main widget
│ ├── chat_message.mustache # Message bubble
│ ├── analytics_dashboard.mustache
│ └── user_settings.mustache
├── amd/src/
│ ├── chat.js # Main controller
│ ├── ui.js # DOM manipulation
│ ├── sse_client.js # SSE streaming
│ ├── markdown.js # MD to HTML
│ ├── audio_player.js # TTS playback
│ └── repository.js # AJAX wrappers
├── styles.css # Widget styles
├── pix/
│ ├── icon.svg # Plugin icon
│ └── avatars/ # 10 avatar SVGs
└── tests/
├── context_builder_test.php
├── conversation_manager_test.php
└── behat/
└── chat_widget.feature
-
Claude (Anthropic)
- Models: claude-sonnet-4, claude-opus-4, claude-haiku-4
- API:
https://api.anthropic.com
-
OpenAI
- Models: gpt-4o, gpt-4-turbo, gpt-3.5-turbo
- API:
https://api.openai.com
-
Ollama (Self-Hosted)
- Models: llama3, mistral, codellama, etc.
- API:
http://localhost:11434(default)
-
MiniMax
- Models: MiniMax-Text-01
- API:
https://api.minimax.chat
-
Custom OpenAI-Compatible
- Any API following OpenAI's chat completions format
- Configure max history to control token usage
- Use rate limiting to prevent runaway costs
- Monitor usage in analytics dashboard
- Consider self-hosted options (Ollama) for unlimited use
- ✅ System prompt caching (1 hour)
- ✅ Rate limiting (user + IP)
- ✅ Gzip compression for responses
- ✅ Database query optimization with indexes
- ✅ Lazy loading of chat widget JS
- ✅ Efficient SSE streaming
- ✅ Session write-close to prevent blocking
- Widget load: <100ms
- Message send (cached prompt): ~200ms + AI provider latency
- SSE streaming: Real-time token delivery
- Analytics dashboard: <500ms (typical course)
- Check plugin is enabled in settings
- Verify you have
local/ai_course_assistant:usecapability - Ensure you're on a course page (not site home)
- Check browser console for JavaScript errors
- Verify web server doesn't buffer SSE responses
- For nginx: Add
X-Accel-Buffering: no(already in code) - For Apache: Disable mod_deflate for SSE endpoint
- Check firewall/proxy settings
- Increase limits in rate_limiter.php defaults
- Clear rate limit cache: Purge caches → All caches
- Check for API rate limits from provider
- Web Speech API not supported in all browsers
- Try Chrome, Edge, or Safari (best support)
- Check browser permissions for audio
# PHPUnit
php admin/tool/phpunit/cli/init.php
vendor/bin/phpunit local/ai_course_assistant/tests/
# Behat
php admin/tool/behat/cli/init.php
vendor/bin/behat --tags=@local_ai_course_assistant- Follow Moodle coding style guidelines
- Use
phpcbffor automatic fixes - Run
phpcsbefore committing
- Mobile app support
- Voice input
- Image analysis
- PDF document ingestion
- Collaborative study groups
- Advanced analytics (sentiment analysis)
- A/B testing framework
- Custom prompt templates per course
- Integration with H5P activities
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Follow Moodle coding standards
- Add tests for new functionality
- Submit a pull request
- Documentation: See SECURITY.md for compliance details
- Issues: GitHub Issues
- Email: [Your support email]
Author: [Your name/organization] Contributors: [List contributors] License: GNU GPL v3 or later Copyright: 2025 AI Course Assistant
- Moodle community for the excellent platform
- Anthropic for Claude API
- OpenAI for GPT models
- All contributors and testers
Note: This plugin is in BETA. Use in production environments at your own risk. Always test thoroughly in a staging environment first.