Skip to main content
Big news! Interval has been acquired by Meter. Learn more →

Notifications

Interval supports sending custom email or Slack notifications from within your actions via ctx.notify.

A notification is composed of a message containing the primary body of the notification, an optional title, and a delivery array specifiying any number of recipients.

import { Action, ctx } from "@interval/sdk";

export default new Action(async () => {
// ... logic to create a comment
await ctx.notify({
message: `A comment has been posted on ${article.title}: ${comment.body}`,
title: "New comment",
});
});

When the delivery array is not provided, the notification will be sent to the default recipient for the action. This is configured in the dashboard and defaults to the action runner.

Notifications are only delivered for actions in the Production environment. In Development, the content and recipients of ctx.notify calls will be logged in the action's toolbar at the bottom of the page, but the notifications will not actually be sent.

Delivery

info

To enable Slack notifications, you'll need to connect your Slack workspace to the Interval app in your organization settings.

Each delivery entry is composed of a to address (who the notification should be delivered to) and a method (how the notification should be sent). Currently Interval supports EMAIL and SLACK as notification methods, but let us know if there are additional notification channels that would be useful to you.

import { Action, ctx } from "@interval/sdk";

export default new Action(async () => {
// ... logic to invite user
await ctx.notify({
message: `${userEmail} has been invited to the beta`,
title: "New beta user onboarded",
delivery: [
{
to: "foo@example.com",
method: "EMAIL",
},
{
to: "bar@example.com",
},
{
to: "#beta-invites",
method: "SLACK",
},
{
to: "@alex",
method: "SLACK",
},
{
to: "baz@example.com",
method: "SLACK",
},
],
});
});

If an Interval user's email address is provided as the to address, the method property for the recipient is optional. If method is not provided, Interval will deliver the notification via the user's preferred notification method configured in the dashboard.

The to address for Slack recipients may be a channel (#beta-invites), a Slack user handle (@alex), or the email of a Slack user in your workspace.

Sending notifications from anywhere

In addition to sending notifications from within actions, you can also use Interval's notification architecture to quickly send notifications from anywhere in your codebase with the notify method on instances of the Interval class. For example, you could use this API to alert a Slack channel from your user-facing app when someone signs up.

When sending notifications using interval.notify(), the delivery array is required.

import { Interval } from "@interval/sdk";

const interval = new Interval({
endpoint: "wss://<YOUR INTERVAL SERVER URL>/websocket",
apiKey: "<YOUR API KEY>", // get an API key from the Keys page in your Interval dashboard
});

async function handleNewComment(article, comment) {
try {
await interval.notify({
title: "New comment",
message: `A new comment was posted on ${article.title}: ${comment.body}`,
delivery: [{ to: "#article-comments", method: "SLACK" }],
});
} catch (err) {
console.error(
"Could not send notification. Does this Slack channel exist?",
err
);
}
}

If the notification is undeliverable, e.g. due to an invalid recipient in the delivery array, an alert will automatically be sent to the organization owner.

Like notifications sent from within actions, these notifications are only sent in the Production environment (when the Interval class is initialized with a Live mode key).

Automatic notifications

Under certain conditions and while an action is backgrounded, Interval will automatically notify the person running the action through their preferred notification method.

This may happen:

  • When input is required for the action to continue running.
  • When the action execution completes.
Was this section useful?