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

Create an example Gmail job which uses an HTTP endpoint / trigger #126

Closed
D-K-P opened this issue Nov 30, 2023 · 1 comment · Fixed by #132
Closed

Create an example Gmail job which uses an HTTP endpoint / trigger #126

D-K-P opened this issue Nov 30, 2023 · 1 comment · Fixed by #132

Comments

@D-K-P
Copy link
Member

D-K-P commented Nov 30, 2023

Overview

HTTP endpoints allow you to subscribe to changes from an API. You can use defineHttpEndpoint to receive webhooks, verify them, and create an HTTP Trigger.

Details:

The task is to create a job example which is triggered by an HTTP Trigger when a change is received from Gmail.

Reference material:

  • Read our HTTP endpoints docs
  • Read our SDK reference docs
  • Check out our simple Cal.com example. This is a simple implementation.
  • Check out our WhatsApp example. This is a more advanced implementation (using respondWith) because WhatsApp sends a verification GET request to confirm before the webhooks can be created. Most APIs don't required this.

Requirements:

  • Use the structure of our Cal.com example.
  • The example must connect to Gmail, receive a payload which triggers an HTTP Trigger, and then perform a simple job.

Guidelines:

  • The code must use TypeScript
  • The job must use an HTTP Trigger
  • Create a TypeScript type for the webhook, ideally use types from the official SDK from the API.
  • Cast the json to that type using const body = await request.json() as WebhookPayload
  • Use native fetch where no official SDK or incompatible auth
  • Avoid external packages apart from official SDKs
  • Prefer REST over GraphQL - avoid raw queries
  • Use a minimal io.runTask() callback - initialise clients and auth in global scope if possible
  • Leave clear comments with links to relevant developer docs, API key pages etc.

Required structure:

  1. Follow this guide to get the project setup.​

  2. Create a new file in the src folder, named to match the API, with '-http-endpoint' at the end (e.g. GitHub would be called github-http-endpoint.ts).​

  3. The Trigger.dev client must be defined at the top of the job, with the 'api-reference' id:

const client = new TriggerClient({ id: "api-reference" });


4. You must add the Express specific lines to the bottom of the Job file:

// These lines can be removed if you don't want to use express
import { createExpressServer } from "@trigger.dev/express";
createExpressServer(client);


5. You must add the new script to the package.json file, in this format:

"scripts": {
  //..other scripts
  "<api-name>": "nodemon --watch src/<api name>.ts -r tsconfig-paths/register -r dotenv/config src/<api name>.ts"
}

Important

You must test this Job works before submitting your PR, including a video or screenshot of a successful run. This may involve you having to setup accounts with services.

biplobsd added a commit to biplobsd/api-reference that referenced this issue Dec 1, 2023
@D-K-P D-K-P closed this as completed in #132 Dec 5, 2023
D-K-P pushed a commit that referenced this issue Dec 5, 2023
* Added gmail http endpoint example (#126)

* added comments
Copy link

algora-pbc bot commented Dec 9, 2023

🎉🎈 @biplobsd has been awarded $50! 🎈🎊

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

Successfully merging a pull request may close this issue.

1 participant