I am working with an external API and need to consume its webhook notifications.
This external service will include in the notification a "secret", a static string for verification purpose AND "type of notification", the type can be (those are pure examples) :
- verification-approved
- verification-failed
- payment-approved
- delivery-confirmed
- etc ...
So I first have to verify if the secret matches mine then run some work (mostly database) based on the notification type.
I would like your recommendations on the optimal approach to consume these webhook notifications.
My only idea is having multiple ifs in the code, an if to check the secret and n ifs to check notification type and run the corresponding work.
Here is an example of a webhook notification :
{ enduser_id: 'xxxxxxxx',
owner: 'xxxxxxxxx',
type: 'verification-approved',
created_at: '2020-11-09T19:00:35.944Z',
notification_id: 'yyyyyyyyyy',
secret:
'the_secret' }
Aucun commentaire:
Enregistrer un commentaire