This directory contains example plugins that demonstrate various features of the ZephyrGate plugin system. Each plugin showcases different capabilities and best practices for plugin development.
Purpose: Minimal example demonstrating basic plugin functionality
Features Demonstrated:
- Command registration
- Message handling
- Configuration access
- Scheduled tasks
- Data storage
- Mesh messaging
Commands:
hello- Say hello to the mesh networkgreet <name>- Greet a specific user
Configuration:
plugins:
hello_world:
enabled: true
greeting_message: "Greetings"
greeting_interval: 3600
periodic_greeting_enabled: falseUse Case: Starting point for new plugin developers
Purpose: Demonstrates HTTP requests and scheduled data fetching
Features Demonstrated:
- HTTP client usage (simulated)
- Scheduled task execution
- Data caching with TTL
- Configuration management
- Error handling for network requests
- Alert system
Commands:
weather <location>- Get current weatherweatheralert [location]- Check for weather alertsweatherconfig- Show configuration
Configuration:
plugins:
weather_alert:
enabled: true
default_location: "San Francisco"
check_interval: 1800 # 30 minutes
alerts_enabled: true
temp_threshold: 35 # Celsius
wind_threshold: 50 # km/h
alert_types:
- severe
- warningUse Case: Plugins that need to fetch external data periodically and send alerts
Purpose: Demonstrates BBS menu integration
Features Demonstrated:
- Menu item registration
- Multiple menu locations
- Admin-only menu items
- Menu handler context access
- Dynamic menu ordering
Menu Items:
- Utilities → Plugin Demo
- Utilities → Admin Demo (admin only)
- Main → Quick Demo
Configuration:
plugins:
menu_example:
enabled: trueUse Case: Plugins that provide interactive BBS menu interfaces
Purpose: Demonstrates plugin storage capabilities
Features Demonstrated:
- Storing and retrieving data
- Data persistence across restarts
- TTL (Time To Live) for cached data
- Data querying and filtering
- Statistics tracking
- Export functionality
- Automatic message logging
Commands:
log <type> <message>- Log a message (types: info, warning, error, event)logquery [type] [limit]- Query logged datalogstats- Show logging statisticslogexport [type] [limit]- Export logged datalogclear <type|all>- Clear logged data
Configuration:
plugins:
data_logger:
enabled: true
auto_log_messages: true
max_stored_entries: 1000Use Case: Plugins that need to store and query historical data
Purpose: Demonstrates multiple command handlers with different patterns
Features Demonstrated:
- Multiple command registration
- Different priority levels
- Argument parsing and validation
- Context usage
- Help system
- Command usage tracking
Commands:
echo <message>- Echo back a message (high priority)time [format]- Show current time (formats: utc, local, unix)calc <op> <n1> <n2>- Simple calculator (operations: add, sub, mul, div)reverse <text>- Reverse a stringcount <type> <text>- Count words or characters (types: words, chars)info- Show message context informationhelp [command]- Show help informationfallback- Low priority fallback handler
Configuration:
plugins:
multi_command:
enabled: trueUse Case: Plugins that provide multiple utility commands
Purpose: Demonstrates scheduled task system with multiple schedules
Features Demonstrated:
- Interval-based scheduling
- Cron-style scheduling
- Error handling in scheduled tasks
- Task status monitoring
- Multiple concurrent tasks
Commands:
taskstatus- Show status of all scheduled tasks
Scheduled Tasks:
periodic_update- Runs every 60 secondsfive_minute_report- Runs every 5 minutes (cron: */5 * * * *)error_demo- Demonstrates error handling (runs every 120 seconds)
Configuration:
plugins:
scheduled_task_example:
enabled: trueUse Case: Plugins that need to perform periodic background tasks
Purpose: Demonstrates core service access and inter-plugin messaging
Features Demonstrated:
- Message routing to mesh network
- System state queries
- Inter-plugin messaging
- Permission enforcement
- Broadcasting to all plugins
Commands:
status [node_id]- Get system status informationping <plugin_name>- Ping another pluginbroadcast <message>- Broadcast a message to all pluginsmesh <message> [destination] [channel]- Send message to mesh network
Required Permissions:
send_messagessystem_state_readinter_plugin_messaging
Configuration:
plugins:
core_services_example:
enabled: trueUse Case: Plugins that need to interact with other plugins or access system state
-
Copy the example plugin to your plugins directory:
cp examples/plugins/hello_world_plugin.py plugins/
-
Add configuration to your
config.yaml:plugins: hello_world: enabled: true
-
Restart ZephyrGate or enable the plugin dynamically through the admin interface
-
Test the plugin by sending a command:
hello
- Start with an example that matches your use case
- Copy and rename the example plugin
- Modify the class name and functionality
- Update the configuration section
- Test thoroughly before deployment
- Plugin Development Guide:
docs/PLUGIN_DEVELOPMENT.md - Enhanced Plugin API:
docs/ENHANCED_PLUGIN_API.md - Plugin Template Generator:
docs/PLUGIN_TEMPLATE_GENERATOR.md - Plugin Menu Integration:
docs/PLUGIN_MENU_INTEGRATION.md
async def handle_command(self, args: List[str], context: Dict[str, Any]) -> str:
if not args:
return "Usage: command <arg>"
# Process command
result = process(args)
return f"Result: {result}"async def scheduled_task(self):
try:
# Perform task
data = await fetch_data()
await self.store_data("key", data)
except Exception as e:
self.logger.error(f"Task error: {e}")# Store data
await self.store_data("key", value, ttl=3600)
# Retrieve data
value = await self.retrieve_data("key", default=None)
# Delete data
await self.delete_data("key")try:
data = await self.http_get(url, params={'key': 'value'})
# Process data
except Exception as e:
self.logger.error(f"HTTP error: {e}")async def menu_handler(self, context: Dict[str, Any]) -> str:
user_name = context.get('user_name', 'Unknown')
response = [
"=== Menu Title ===",
f"Hello {user_name}!",
"Menu content here..."
]
return "\n".join(response)- Unit Tests: Test individual methods
- Integration Tests: Test with ZephyrGate core
- Manual Testing: Test commands and functionality
- Error Testing: Test error handling and edge cases
- Error Handling: Always wrap operations in try-except blocks
- Logging: Use
self.loggerfor all log messages - Configuration: Use
self.get_config()for all settings - Storage: Use plugin storage for persistent data
- Documentation: Include docstrings and usage examples
- Cleanup: Properly clean up resources in
stop()method
- Check plugin is in correct directory
- Verify configuration is correct
- Check logs for error messages
- Ensure all dependencies are installed
- Verify command registration in
initialize() - Check command priority conflicts
- Review command handler implementation
- Test with simple echo command first
- Verify task registration
- Check task interval/cron expression
- Review task handler for errors
- Check plugin is started successfully
When contributing example plugins:
- Follow existing code style
- Include comprehensive documentation
- Add configuration examples
- Test thoroughly
- Update this README
These examples are provided under the same license as ZephyrGate.