Email worker template?

From the email workers documentation there's a nice description of how to create a worker. https://developers.cloudflare.com/email-routing/email-workers/ Trying to start a project I'm looking for a typescript template or simply the types. The page links to languages: https://developers.cloudflare.com/workers/platform/languages/ Which links to: https://github.com/cloudflare/workers-types Which is archived - types now live in workerd (which is a C++ repo): https://github.com/cloudflare/workerd From there it's unclear how to use types for email workers in your project. So from following that path it's unclear: How to include the types? And if the answer is "use the regular worker typescript template", that's fine too. Perhaps it would be nice to see this reflected in the docs - I'd be happy to submit a PR for that.
6 Replies
Chaika
Chaika16mo ago
The types should just be in worker types package, EmailMessage https://www.npmjs.com/package/@cloudflare/workers-types Here is the links to the docs for the Email event types: https://developers.cloudflare.com/workers/runtime-apis/email-event/
npm
@cloudflare/workers-types
TypeScript typings for Cloudflare Workers. Latest version: 4.20230221.0, last published: a day ago. Start using @cloudflare/workers-types in your project by running npm i @cloudflare/workers-types. There are 66 other projects in the npm registry using @cloudflare/workers-types.
Webber
Webber16mo ago
I've found those. The question was mostly about how to use those types. But turns out you just use the same template as for other workers.
Chaika
Chaika16mo ago
ahh yea, I don't think there's any typescript examples for email workers, here's a community made example typescript email worker though: https://github.com/Le0Developer/cloudflare-discord-mailing/blob/master/src/email.ts (That has the types hardcoded because it was made a bit ago, but they should all be the exact same as the ones in worker-types now)
Webber
Webber16mo ago
Do you think it would be helpful to mention how to start an email worker project in the docs? It's a bit ambiguous right now and not immediately obvious that it's using the exact same worker types. Yea I've completed most of my worker already (https://github.com/webbertakken/email-worker). Just need a dependency so starting an actual project now.
Chaika
Chaika16mo ago
If you're asking if you should make a PR to add a note like "Email Worker Types are in the same Worker Types package" or an actual example, sure, if you got confused others could too
Webber
Webber16mo ago
Cool. Will consider creating a PR Thanks!