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

additional data on trigger event #14

Open
mrbraca15 opened this issue Jul 11, 2017 · 6 comments
Open

additional data on trigger event #14

mrbraca15 opened this issue Jul 11, 2017 · 6 comments
Labels

Comments

@mrbraca15
Copy link

mrbraca15 commented Jul 11, 2017

hello i need to send a additional data on trigger event for use it after on succes event, for example:

webHooks.trigger(shortName, payloadData, additionalData);

emitter.on('*.success', (shortname, statusCode, body, additionalData)=> {
            //here i need to use the data that i send as parameter in the trigger event
           //how can i do that?
});

thanks

@mrbraca15 mrbraca15 changed the title custom data to trigger event additional data to trigger event Jul 11, 2017
@mrbraca15 mrbraca15 changed the title additional data to trigger event additional data on trigger event Jul 11, 2017
@roccomuso
Copy link
Owner

You can't do this:

webHooks.trigger(shortName, payloadData, additionalData);

The third parameter is reserved for the headers.
If you wanna pass more data, just add it as an additional property of your payloadData object.

Example:

webHooks.trigger(shortName, {myData: 'hello', moreData: 'even more data'});

emitter.on('*.success', (shortname, statusCode, body)=> {
         var myData = body.myData
         var moreData = body.moreData
         // ...
});

@mrbraca15
Copy link
Author

mrbraca15 commented Jul 11, 2017

hello thanks for the answer but in the body parameter i received the request response of the url configured in the shorname.

@roccomuso
Copy link
Owner

Ok, I was supposing that the web-server "mirrors" your body request.
You can't manipulate the server's response.
It's not either a good practice.

@kurdi89
Copy link

kurdi89 commented Mar 15, 2021

webHooks.trigger(shortName, {myData: 'hello', moreData: 'even more data'});

emitter.on('*.success', (shortname, statusCode, body)=> {
         var myData = body.myData
         var moreData = body.moreData
         // ...
});

did the above but the body contains the response body, any help to track what have been sent from my side as in the request body,

thank you

@kurdi89
Copy link

kurdi89 commented Mar 15, 2021

this how i am triggering the webhook :

// dispatch the webhook : 
    await webHooks.trigger('OrderCreated', {data: data}, {Authorization: Authorization});
    

and here is the function I am using to log all the webhooks dispatched :

emitter.on('*.failure', async function (shortname, statusCode, body) {
  let TIMESTAMP = new Date().toLocaleString("en-US", {timeZone: "Asia/Riyadh"});
  let DATE = new Date().toLocaleDateString("en-US", {timeZone: "Asia/Riyadh"}).replace("/","-").replace("/","-").substring(0,9);
  console.log(colors.error('ERROR on trigger webhook ' + shortname + ' with status code', statusCode, 'and body', body , 'At : ',TIMESTAMP))
    
    
    let obj = { 
      shortname,
      statusCode,
      TIMESTAMP,
      body,
    }
    // console.log({obj})
    await (async () => {
        let event = []
        event.push({} = obj)
        const csv = new ObjectsToCsv(event);
      
        // Save to file:
        await csv.toDisk(`./logs/FAILED-WEBHOOKS-${DATE}-${shortname}.csv`, { append: true });
      
        // Return the CSV file as string:
        // console.log(await csv.toString());
    })();
})

anyway to track the body of the request I am dispatching, the data object, thanks again

@roccomuso
Copy link
Owner

it's up to your app logic to keep track of what you're dispatching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants