I am working on a project that involves integrating with the WhatsApp Business API, and I noticed that there are no official TypeScript types for the webhook API. The documentation while detailed, lacks (or i could not find) the type definitions that would make it easier to work with the API in a type-safe manner.
So, I decided to create my own minimal set of types to help me with the integration.
Reverse engineering the webhook payload
The process was pretty simple:
1 - In my app webhook endpoint, i saved the received payloads to a database
2 - From this sample i created the types using a JSON to TypeScript converter
3 - I then refined the types to make them more readable and easier to work with.
Some notes:
The types are not exhaustive, they only cover the message types that I needed for my project i.e, ‘messages’ and ‘message_template_status_update’.
My go to JSON to Typescript converter was from Transform.Tools which is based on json_typegen. But
is lacking creation of enum / union types from fields with repeatable values. Fortunately i found quicktype that supports this feature.