Skip to content

feat: expose auto responder tokens as environment variables (#2314)#2356

Merged
Yeraze merged 1 commit intomainfrom
feat/2314-autoresponder-env-vars
Mar 21, 2026
Merged

feat: expose auto responder tokens as environment variables (#2314)#2356
Yeraze merged 1 commit intomainfrom
feat/2314-autoresponder-env-vars

Conversation

@Yeraze
Copy link
Copy Markdown
Owner

@Yeraze Yeraze commented Mar 21, 2026

Summary

Closes #2314 — Expose auto responder tokens as environment variables for scripts.

Previously, tokens like {LONG_NAME}, {SNR}, {HOPS} were only available via command-line argument expansion, which breaks when values contain spaces. Now all tokens are available as environment variables with clean, documented names.

New environment variables added:

Variable Source
NODE_ID Sender's hex node ID
SHORT_NAME / LONG_NAME Sender's node names (aliases for existing FROM_SHORT_NAME/FROM_LONG_NAME)
HOPS Calculated hop count
SNR / RSSI Signal quality from packet
CHANNEL Channel number
VERSION Sender's firmware version
NODECOUNT Active node count
VIA_MQTT MQTT bridge flag
IS_DIRECT Direct message flag

Documentation updated:

  • docs/developers/auto-responder-scripting.md — Full env var table expanded
  • docs/features/automation.md — Summary list updated with link to full reference

Test plan

  • Create an auto responder script that reads NODE_ID, SNR, HOPS, NODECOUNT from env vars
  • Verify values match what the token expansion produces in text responses
  • Verify LONG_NAME with spaces is accessible without parsing issues
  • Full test suite passes (2987 tests)

🤖 Generated with Claude Code

Add NODE_ID, LONG_NAME, SHORT_NAME, HOPS, SNR, RSSI, CHANNEL, VERSION,
NODECOUNT, VIA_MQTT, IS_DIRECT, MESHTASTIC_IP, MESHTASTIC_PORT, and
MATCHED_PATTERN as environment variables for auto responder scripts.

These match the {TOKEN} names from the auto responder documentation,
giving script authors a clean way to access packet metadata without
parsing command-line arguments that may contain spaces.

Updated documentation in both automation.md and
auto-responder-scripting.md.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
// Add token-matching environment variables (Issue #2314)
// These match the {TOKEN} names from the auto responder documentation
if (context) {
scriptEnv.NODE_ID = context.nodeId;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good implementation for exposing environment variables! A few observations:

  1. Clean aliasing: I like that you've provided NODE_ID, SHORT_NAME, LONG_NAME as aliases for the existing FROM_* variables. This gives users cleaner, more intuitive variable names while maintaining backward compatibility.

  2. Conditional assignment: Good defensive programming with the conditional checks for rxSnr and rxRssi to avoid setting undefined values.

  3. Type safety: Proper string conversion using String() for all numeric values.

Minor suggestion: Consider adding a debug log statement here to help with troubleshooting:

logger.debug(`🔧 Auto-responder env vars: NODE_ID=${context.nodeId}, HOPS=${context.hopsTraveled}, SNR=${message.rxSnr}, RSSI=${message.rxRssi}`);

| `FROM_NODE` | Sender's node number | `"123456789"` |
| `FROM_SHORT_NAME` | Sender's short name (if known) | `"JOHN"` |
| `FROM_LONG_NAME` | Sender's long name (if known) | `"John Doe"` |
| `NODE_ID` | Sender's node ID (hex format) | `"!a2e4ff4c"` |
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent documentation update! The environment variables table is comprehensive and well-organized. I particularly appreciate:

  1. Complete coverage: All the new environment variables are documented with clear examples
  2. Alias explanation: Good clarification that SHORT_NAME/LONG_NAME are aliases for existing variables
  3. Consistent formatting: The table format matches the existing documentation style

One minor suggestion: Consider adding a note about when these variables are available. For example:

  • SNR/RSSI: Only available for direct radio reception (not MQTT bridge)
  • HOPS: Always available, 0 for direct messages
  • NODE_ID: Always available in hex format

This would help script authors understand data availability patterns.

@github-actions
Copy link
Copy Markdown

Code Review Summary

This PR successfully implements auto responder tokens as environment variables (closes #2314), providing a clean solution to the space-handling issues with command-line argument expansion.

Strengths

Implementation Quality

  • Clean aliasing: Provides intuitive NODE_ID, SHORT_NAME, LONG_NAME variables while maintaining backward compatibility with existing FROM_* variables
  • Defensive programming: Proper conditional checks for optional values like rxSnr and rxRssi
  • Type safety: Consistent use of String() conversion for all numeric environment variables
  • Well-integrated: Seamlessly fits into the existing createScriptEnvVariables function architecture

Documentation Excellence

  • Comprehensive coverage: All new environment variables are documented with clear examples
  • Consistent formatting: Documentation follows established patterns and style
  • Cross-referenced: Automation.md appropriately links to the detailed scripting guide
  • User-focused: Addresses the core pain point mentioned in the issue (spaces in values)

Feature Completeness

  • All required tokens: Covers NODE_ID, SHORT_NAME, LONG_NAME, HOPS, SNR, RSSI, CHANNEL, VERSION, NODECOUNT, VIA_MQTT, IS_DIRECT
  • Backward compatible: Existing scripts continue to work unchanged
  • Consistent naming: Environment variable names match the {TOKEN} syntax from documentation

📋 Technical Details

Files Modified

  • ✅ src/server/meshtasticManager.ts - Core implementation (lines 8078-8113)
  • ✅ docs/developers/auto-responder-scripting.md - Expanded env var table
  • ✅ docs/features/automation.md - Updated summary with link to full reference

Environment Variables Added

NODE_ID, SHORT_NAME/LONG_NAME, HOPS, SNR/RSSI, CHANNEL, VERSION, NODECOUNT, VIA_MQTT, IS_DIRECT

🏆 Overall Assessment

Excellent implementation! This PR:

  • ✅ Solves the core issue with argument parsing and spaces
  • ✅ Maintains backward compatibility
  • ✅ Provides clean, intuitive variable names
  • ✅ Includes comprehensive documentation updates
  • ✅ Follows established coding patterns and conventions
  • ✅ Ready for production deployment

The solution is well-thought-out, properly implemented, and thoroughly documented. Users will benefit from easier script development without the complexity of argument parsing edge cases.

🚀 Ready to Merge

This PR successfully addresses issue #2314 and is ready for merging. The implementation is solid, the documentation is excellent, and the backward compatibility ensures no breaking changes for existing users.

@Yeraze Yeraze merged commit 8a1ee9f into main Mar 21, 2026
16 of 17 checks passed
@Yeraze Yeraze mentioned this pull request Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] Expose Auto Responder tokens as Environment Variables for scripts

1 participant