Skip to content

Instantly share code, notes, and snippets.

@rikonor
Created December 1, 2025 02:22
Show Gist options
  • Select an option

  • Save rikonor/7021e5896bcb55d5840a197d0d00dd52 to your computer and use it in GitHub Desktop.

Select an option

Save rikonor/7021e5896bcb55d5840a197d0d00dd52 to your computer and use it in GitHub Desktop.
So many things
#!/usr/bin/env bash
call-workflow() {
local N8N_BASE_URL="http://n8n:5678/webhook/"
if [ -z "$1" ]; then
echo "Error: Workflow ID required."
return 1
fi
local WORKFLOW_ID=$1
local FULL_URL="${N8N_BASE_URL}${WORKFLOW_ID}"
local PAYLOAD=${2:-'{}'}
CURL_OUTPUT=$(curl -s -X POST -H "Content-Type: application/json" -d "$PAYLOAD" "$FULL_URL")
local curl_status=$?
if [ $curl_status -ne 0 ]; then
echo "Error: Workflow call failed: $curl_status" >&2
return 1
fi
echo "$CURL_OUTPUT"
}
double-number() {
if [ -z "$1" ]; then
echo "Error: Number argument required."
return 1
fi
local number=${1//\'/}
local WORKFLOW_ID="a60d3593-d24b-4577-a079-ca13f94535a0"
local PAYLOAD="{\"number\": $number}"
response=$(call-workflow "$WORKFLOW_ID" "$PAYLOAD")
local call_status=$?
if [ $call_status -ne 0 ]; then
return $call_status
fi
# Process the successful response using jq
local value
value=$(echo "$response" | jq -r '.value')
local jq_status=$?
if [ $jq_status -ne 0 ]; then
echo "Error: Failed to parse JSON response with jq (Response: $response)." >&2
return 1
fi
echo "$value"
}
get-weather() {
if [ -z "$1" ]; then
echo "Error: City argument required."
return 1
fi
local city=${1//\'/}
local WORKFLOW_ID="01dd473f-6623-4523-968d-04efbbaafdda"
local PAYLOAD="{\"city\": \"$city\"}"
response=$(call-workflow "$WORKFLOW_ID" "$PAYLOAD")
local call_status=$?
if [ $call_status -ne 0 ]; then
return $call_status
fi
# Process the successful response using jq
local value
value=$(echo "$response" | jq -r '.message' | base64 -d | pandoc -f html -t markdown | glow)
local jq_status=$?
if [ $jq_status -ne 0 ]; then
echo "Error: Failed to parse JSON response with jq (Response: $response)." >&2
return 1
fi
echo "$value"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment