Project setup
Install dependencies: axios or node-fetch for HTTP calls, and zod for webhook payload validation. Create a chatapi.ts file with TypeScript types for Chat API messages, templates and webhooks.
TypeScript client for Chat API
Create a ChatAPIClient class with async methods for each main operation. Implement retry with exponential backoff to handle rate limits.
Webhook validation with Zod
Use Zod to validate and type webhook payloads at runtime: define a Zod schema for each webhook event type.
Testing with TypeScript
Use Jest with ts-jest for TypeScript tests. Mock HTTP calls with jest.spyOn. Test both success cases and errors.