You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+27Lines changed: 27 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -113,6 +113,33 @@ You can also force streaming mode for any endpoint using the `--stream` or `-s`
113
113
xurl -s /2/users/me
114
114
```
115
115
116
+
### Temporary Webhook Setup
117
+
118
+
`xurl` can help you quickly set up a temporary webhook URL to receive events from the X API. This is useful for development and testing.
119
+
120
+
1.**Start the local webhook server with ngrok:**
121
+
122
+
Run the `webhook start` command. This will start a local server and use ngrok to create a public URL that forwards to your local server. You will be prompted for your ngrok authtoken if it's not already configured via the `NGROK_AUTHTOKEN` environment variable.
123
+
124
+
```bash
125
+
xurl webhook start
126
+
# Or with a specific port and output file for POST bodies
127
+
xurl webhook start -p 8081 -o webhook_events.log
128
+
```
129
+
130
+
The command will output an ngrok URL (e.g., `https://your-unique-id.ngrok-free.app/webhook`). Note this URL.
131
+
132
+
2. **Register the webhook with the X API:**
133
+
134
+
Use the ngrok URL obtained in the previous step to register your webhook. You'll typically use app authentication for this.
135
+
136
+
```bash
137
+
# Replace https://your-ngrok-url.ngrok-free.app/webhook with the actual URL from the previous step
Your local `xurl webhook start` server will then handle the CRC handshake from Twitter and log incoming POST events (and write them to a file if `-o` was used).
142
+
116
143
### Media Upload
117
144
118
145
The tool supports uploading media files to the X API using the chunked upload process.
Long: `Manages X API webhooks. Currently supports starting a local server with an ngrok tunnel to handle CRC checks.`,
36
+
}
37
+
38
+
webhookStartCmd:=&cobra.Command{
39
+
Use: "start",
40
+
Short: "Start a local webhook server with an ngrok tunnel",
41
+
Long: `Starts a local HTTP server and an ngrok tunnel to listen for X API webhook events, including CRC checks. POST request bodies can be saved to a file using the -o flag. Use -q for quieter console logging of POST events. Use -p to pretty-print JSON POST bodies in the console.`,
42
+
Run: func(cmd*cobra.Command, args []string) {
43
+
color.Cyan("Starting webhook server with ngrok...")
log.Printf("[INFO] POST body written to %s", color.GreenString(outputFileName))
164
+
}
165
+
}
166
+
167
+
w.WriteHeader(http.StatusOK)
168
+
} else {
169
+
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
170
+
}
171
+
})
172
+
173
+
color.Cyan("Starting local HTTP server to handle requests from ngrok tunnel (forwarded from %s)...", color.HiGreenString(ngrokListener.URL()))
174
+
iferr:=http.Serve(ngrokListener, nil); err!=nil {
175
+
iferr!=http.ErrServerClosed {
176
+
color.Red("HTTP server error: %v", err)
177
+
os.Exit(1)
178
+
} else {
179
+
color.Yellow("HTTP server closed gracefully.")
180
+
}
181
+
}
182
+
color.Yellow("Webhook server and ngrok tunnel shut down.")
183
+
},
184
+
}
185
+
186
+
webhookStartCmd.Flags().IntVarP(&webhookPort, "port", "p", 8080, "Local port for the webhook server to listen on (ngrok will forward to this port)")
187
+
webhookStartCmd.Flags().StringVarP(&outputFileName, "output", "o", "", "File to write incoming POST request bodies to")
188
+
webhookStartCmd.Flags().BoolVarP(&quietMode, "quiet", "q", false, "Enable quiet mode (logs only that a POST event was received, not the full body to console)")
189
+
webhookStartCmd.Flags().BoolVarP(&prettyMode, "pretty", "P", false, "Pretty-print JSON POST bodies in console output (ignored if -q is used)")
0 commit comments