Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webhook should include addtional information in the call #12

Closed
jhorbulyk opened this issue Jul 10, 2019 · 5 comments
Closed

Webhook should include addtional information in the call #12

jhorbulyk opened this issue Jul 10, 2019 · 5 comments
Assignees

Comments

@jhorbulyk
Copy link
Contributor

Create the following flow:

  1. Webhook: No Auth
  2. Code Component: Default code
// Please note only Node.js code is supported here
async function run(msg) {
	console.log('Incoming message is %s', JSON.stringify(msg));
	const body = { result : 'Hello world!' };
	// You can emit as many data messages as required
	await this.emit('data', { body });
	console.log('Execution finished');
}

Publish and start the flow and then call the webhook with:
https://in.elastic.io/hook/5d25e4598370bfb1c7c4696a/Something?abc=def
Observe the incoming message in the code component. It is:

{
  "id": "c88fa000-a314-11e9-a435-dddac8c424fb",
  "attachments": {
    
  },
  "body": {
    "abc": "def",
    "_query": {
      "abc": "def"
    }
  },
  "headers": {
    "host": "in.elastic.io",
    "x-request-id": "c2ddbdbc20c95ff4518e065a18892e82",
    "x-real-ip": "88.130.157.228",
    "x-forwarded-for": "88.130.157.228",
    "x-forwarded-host": "in.elastic.io",
    "x-forwarded-port": "443",
    "x-forwarded-proto": "https",
    "x-original-uri": "\/hook\/5d25e4598370bfb1c7c4696a\/Something?abc=def",
    "x-scheme": "https",
    "upgrade-insecure-requests": "1",
    "user-agent": "Mozilla\/5.0 (X11; Linux x86_64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/75.0.3770.100 Safari\/537.36",
    "accept": "text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/webp,image\/apng,*\/*;q=0.8,application\/signed-exchange;v=b3",
    "accept-encoding": "gzip, deflate, br",
    "accept-language": "en-US,en;q=0.9,de-DE;q=0.8,de;q=0.7,fr;q=0.6"
  },
  "metadata": {
    
  },
  "url": "\/hook\/5d25e4598370bfb1c7c4696a\/Something?abc=def",
  "method": "GET",
  "originalUrl": "\/hook\/5d25e4598370bfb1c7c4696a\/Something?abc=def",
  "query": {
    "abc": "def"
  },
  "params": {
    
  },
  "pathSuffix": "\/hook\/5d25e4598370bfb1c7c4696a\/Something",
  "taskId": "5d25e4598370bfb1c7c4696a",
  "passthrough": {
    "step_1": {
      "id": "c88fa000-a314-11e9-a435-dddac8c424fb",
      "attachments": {
        
      },
      "body": {
        "abc": "def",
        "_query": {
          "abc": "def"
        }
      },
      "headers": {
        "host": "in.elastic.io",
        "x-request-id": "c2ddbdbc20c95ff4518e065a18892e82",
        "x-real-ip": "88.130.157.228",
        "x-forwarded-for": "88.130.157.228",
        "x-forwarded-host": "in.elastic.io",
        "x-forwarded-port": "443",
        "x-forwarded-proto": "https",
        "x-original-uri": "\/hook\/5d25e4598370bfb1c7c4696a\/Something?abc=def",
        "x-scheme": "https",
        "upgrade-insecure-requests": "1",
        "user-agent": "Mozilla\/5.0 (X11; Linux x86_64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/75.0.3770.100 Safari\/537.36",
        "accept": "text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/webp,image\/apng,*\/*;q=0.8,application\/signed-exchange;v=b3",
        "accept-encoding": "gzip, deflate, br",
        "accept-language": "en-US,en;q=0.9,de-DE;q=0.8,de;q=0.7,fr;q=0.6"
      },
      "metadata": {
        
      },
      "url": "\/hook\/5d25e4598370bfb1c7c4696a\/Something?abc=def",
      "method": "GET",
      "originalUrl": "\/hook\/5d25e4598370bfb1c7c4696a\/Something?abc=def",
      "query": {
        "abc": "def"
      },
      "params": {
        
      },
      "pathSuffix": "\/hook\/5d25e4598370bfb1c7c4696a\/Something",
      "taskId": "5d25e4598370bfb1c7c4696a"
    }
  }
}

Observe that

  • msg.headers contains all the HTTP headers sent in the request
  • msg.url contains the URL that was called, including additional data as part of the path
  • msg.method contains the HTTP verb of the call

Ideally, all of that should be added to the body of the message emitted from webhook so that it is instead:

{
    "abc": "def",
    "_query": {
      "abc": "def"
    },
    "_headers: {
        ...
    },
    "_method": "GET",
    "_url": "\/hook\/5d25e4598370bfb1c7c4696a\/Something?abc=def",
    "_additionalUrlPath": "\/Something"
}
@jhorbulyk jhorbulyk changed the title Webhook should include addtional information in the call. Webhook should include addtional information in the call Jul 10, 2019
@ShkarupaNick
Copy link

Estimation according to Definition of DONE.
Rewriting tests
Code styling
small refactoring (migration to es6 code)

@A3a3e1 A3a3e1 added this to the Sprint #20 milestone Jul 12, 2019
@shanthoshp
Copy link
Contributor

In addition to writing new unit tests, would you like me to refactor the existing one so that it uses chai, nock and sinon?

@shulkaolka
Copy link
Contributor

@shanthoshp, yes, it is point Rewriting tests.

@jhorbulyk
Copy link
Contributor Author

Completed in #14

@jhorbulyk
Copy link
Contributor Author

Not fully done. Re-opening.

@jhorbulyk jhorbulyk reopened this Aug 29, 2019
@A3a3e1 A3a3e1 modified the milestones: Sprint #20, Sprint #23 Sep 2, 2019
@A3a3e1 A3a3e1 removed this from the Sprint #23 milestone Sep 13, 2019
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

No branches or pull requests

6 participants