Advanced Command Example
Create powerful commands with parameters, API integrations, and conditional logic using Command Studio
Prerequisites: Make sure you have completed the Simple Command Example first. This guide builds upon those basics.
Weather Command Example
We'll create a weather command that fetches real-time weather data from an external API. This demonstrates parameters, API calls, error handling, and dynamic responses.
/weather
Get current weather information for any city
Usage: /weather city:"London"
Response: "London: 18°C, Partly Cloudy"
Step 1: Create New Command
Open Command Studio
Navigate to your dashboard → Command Studio → Click "New Command"
Set Basic Information
Fill in the command details:
Name: weather
Description: Get current weather for a city
Trigger Type: Slash Command
Step 2: Add Parameters
Configure Parameters
In the Command Studio, click "Add Parameter" and configure:
Parameter Name |
Type |
Required |
Description |
city |
String |
Yes |
Name of the city to get weather for |
Parameter Types: You can use String, Number, Boolean, or User types. Each parameter becomes available as a variable in your command logic.
Step 3: Build the Flow
Add HTTP Request Action
Drag the "HTTP Request" action from the actions panel into your flow. Configure it:
Method: GET
URL: https://api.weatherapi.com/v1/current.json
Query Parameters:
- key: YOUR_API_KEY
- q: {city}
- aqi: no
API Key Security: Never expose your API keys in client-side code. Use environment variables or secure configuration in Command Studio.
Step 4: Add Conditional Logic
Add Condition Node
Drag a "Condition" node and connect it after the HTTP request. Set the condition:
Condition: {http_response.status} equals 200
If True: Continue to success message
If False: Show error message
Step 5: Add Response Actions
Success Response
Add a "Send Message" action for the success case:
Message: {city}: {http_response.data.current.temp_c}°C, {http_response.data.current.condition.text}
Error Response
Add another "Send Message" action for the error case:
Message: Sorry, I couldn't get weather data for {city}. Please check the city name and try again.
Step 6: Test and Deploy
Test Your Command
Use the Command Studio preview panel to test with different cities:
Test Cases:
- /weather city:"London"
- /weather city:"New York"
- /weather city:"Invalid City"
Pro Tip: Use the debug panel to see the exact API response and troubleshoot any issues.
Advanced Features
Error Handling
- Try/Catch Blocks: Wrap API calls in error handling
- Timeout Settings: Set reasonable timeouts for external requests
- Fallback Responses: Provide alternative responses when services are down
Rate Limiting
- Cooldown Settings: Prevent spam by limiting command usage
- User-based Limits: Track usage per user
- Global Limits: Control overall command frequency
Data Processing
- Variable Manipulation: Format and transform API responses
- Array Operations: Handle lists and multiple results
- String Formatting: Create beautiful, formatted responses
Best Practices
- Always validate input: Check parameter values before using them
- Handle errors gracefully: Provide helpful error messages
- Use meaningful variable names: Make your flows easy to understand
- Test thoroughly: Try edge cases and error conditions
- Document your commands: Add clear descriptions for users
Troubleshooting
Common Issues:
- API Key Issues: Check if your API key is valid and has proper permissions
- Network Errors: Verify internet connectivity and API endpoint availability
- Parameter Problems: Ensure parameters are properly defined and accessible
- Response Format: Check if the API response structure matches your expectations
Next Steps: Try creating commands with multiple parameters, database integration, or complex conditional logic!