IO
io.registerTrigger()
io.registerTrigger()
allows you to register a DynamicTrigger with the specified trigger data.
This has been deprecated in favor of DynamicTrigger.register
Parameters
cacheKey
string
requiredShould be a stable and unique cache key inside the run()
. See
resumability for more information.
dynamicTrigger
DynamicTrigger
requiredA DynamicTrigger that will trigger any Jobs itβs attached.
id
string
requiredA unique id for the registration. This is used to identify and unregister later.
params
object
requiredThe params for the DynamicTrigger. These will vary depending on the type of the DynamicTrigger.
Returns
A Promise that resolves to an object with the following fields:
id
string
requiredA unique id for the registration. This is used to identify and unregister later.
key
string
requiredThe key of the registration.
Example
//1. create a DynamicTrigger
const dynamicOnIssueOpenedTrigger = client.defineDynamicTrigger({
id: "github-issue-opened",
event: events.onIssueOpened,
source: github.sources.repo,
});
//2. create a Job that is attached to the dynamic trigger
client.defineJob({
id: "listen-for-dynamic-trigger",
name: "Listen for dynamic trigger",
version: "0.1.1",
trigger: dynamicOnIssueOpenedTrigger,
integrations: {
slack,
},
run: async (payload, io, ctx) => {
await io.slack.postMessage("Slack π", {
text: `New Issue opened on repo: ${payload.issue.html_url}. \n\n${JSON.stringify(ctx)}`,
channel: "C04GWUTDC3W",
});
},
});
client.defineJob({
id: "new-repo",
name: "New repo",
version: "0.1.1",
trigger: github.triggers.org({
event: events.onNewRepository,
org: "triggerdotdev",
}),
run: async (payload, io, ctx) => {
//3. Register the dynamic trigger so you get notified when an issue is opened
return await io.registerTrigger(
"register-repo",
dynamicOnIssueOpenedTrigger,
payload.repository.name,
{
owner: payload.repository.owner.login,
repo: payload.repository.name,
}
);
},
});
Was this page helpful?