1. Functions
  2. Loops, Conditionals…

Currently, we don’t have anything special for loops or conditionals. You can just write plain-old TypeScript code and it will Just Work™.

Loops

When you perform an action (sendEvent, delays, etc.) inside of a loop, make sure to create unique keys for each action to make sure that your workflows are Resumable:

for (let i = 0; i < 10; i++) {
  await ctx.waitFor(`Wait ${i}`, { seconds: 30 });

  await slack.postMessage(`⭐️ New Star ${i}`, {
    channelName: "github-stars",
    text: `@${starredBy} just starred ${repoName}!`,
  });
}

Parallel Execution

You can run actions in parallel using Promise.all, like so:

await Promise.all(
  messages.map((message) =>
    slack.postMessage(message.id, {
      channelName: "github-stars",
      text: message.text,
    })
  )
);

Conditionals

You can use if statements to conditionally execute code, just like normal code:

if (ctx.event.payload.action === "opened") {
  await slack.postMessage("New Issue", {
    channelName: "github-issues",
    text: `@${ctx.event.payload.sender.login} just opened an issue!`,
  });
}