Skip to content

Conversation

@m-rosinsky
Copy link
Contributor

Add Temporary Webhook Server with Ngrok Integration

This PR introduces a new webhook start command to xurl, enabling users to quickly set up a temporary local server to receive and inspect X API webhook events. This is particularly useful for development and testing webhook integrations.

Features Added:

  • Local Webhook Server (xurl webhook start):

    • Starts an HTTP server that listens for incoming webhook events.
    • Automatically handles X API CRC (Cyclic Redundancy Check) GET requests using the configured OAuth 1.0a consumer secret.
    • Logs incoming GET (CRC) and POST (event) requests to the console.
  • Ngrok Integration:

    • Prompts the user for their ngrok authtoken (can also use the NGROK_AUTHTOKEN environment variable).
    • Establishes an ngrok tunnel, exposing the local webhook server to the internet via a public URL.
    • Displays the generated public ngrok URL, which can then be used to register the webhook with the X API.
  • Console Output Enhancements:

    • Informational messages, prompts, and URLs are now colorized for improved readability.
  • New Command-Line Options for xurl webhook start:

    • --port <number> (-p): Specifies the local port for the webhook server (ngrok will forward to this port, defaults to 8080).
    • --output <filename> (-o): Appends the raw body of all incoming POST requests to the specified file.
    • --quiet (-q): Reduces console verbosity for POST events. Only logs that an event was received, not the full body.
    • --pretty (-P): If a POST request body is JSON and quiet mode is not enabled, it will be pretty-printed and colorized in the console for easier inspection.
  • Documentation:

    • Added a new section to README.md detailing the temporary webhook setup process, including how to start the server and register the ngrok URL with the X API.

How to Use:

  1. Ensure OAuth 1.0a credentials (especially consumer secret) are configured:
    xurl auth oauth1 --consumer-key ... --consumer-secret ...
  2. Start the webhook server:
    xurl webhook start
    (Optionally use -p, -o, -q, -P flags)
  3. Provide ngrok authtoken when prompted.
  4. Use the displayed ngrok URL (e.g., https://<unique-id>.ngrok-free.app/webhook) to register your webhook with the X API:
    xurl --auth app /2/webhooks -d '{"url": "https://<your-ngrok-url>/webhook"}' -X POST

This feature streamlines the process of testing X API webhooks by handling the local server setup, ngrok tunneling, and CRC responses automatically.

@CLAassistant
Copy link

CLAassistant commented May 6, 2025

CLA assistant check
All committers have signed the CLA.

@m-rosinsky m-rosinsky self-assigned this May 6, 2025
@m-rosinsky m-rosinsky merged commit 0cc3d7e into main May 6, 2025
2 checks passed
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.

5 participants