runTask
You should add arunTask()
function to your integration, before adding individual Tasks. It will be used by all Tasks, and allows users to use any function in the official SDK as a Task.
Matching the original SDK structure
The structure of the integrtion should closely map to the official Node SDK for that API.API | Official SDK | Trigger.Dev Task |
---|---|---|
GitHub (octokit) | client.rest.issues.create | io.github.issues.create |
Typeform | client.forms.get | io.typeform.forms.get |
OpenAI | client.completions.create | io.openai.completions.create |
Adding Tasks
Any tasks you add will use therunTask
function you added above.
Remember we want to structure our integration to match the original SDK. If an SDK has a client.forms.get
function, we want to add a myintegration.forms.get
task.
This requires adding a bit of structure to the SDK, to add the Forms object, the get function and use runTask
inside them.
Create the structure
In this example, we’ll addio.github.issues.create
. This will allow users to create a GitHub issue in their jobs.
Comments inline are for instructional purposes only, and should not be included in your final code.
integration/github/issues.ts
Notice how the params are the second argument, that’s because the first argument is always the
task key. See our Keys and Resumability docs for more on
why this is important.
integrations/github/index.ts
onError
function
You can optionally have logic in the onError
param. See the reference for runTask for more info.
The GitHub integration uses this to retry rate-limited requests when the rate limit resets:
integrations/github/index.ts