Get Started
6 Trigger a Webhook

Step 6 - Trigger a Webhook

Enable the basic webhook

In src/index.js, uncomment the import of ./basicWebhook.

import "./helloWorld";
import "./helloSlack";
import "./basicWebhook";
// import "./githubToSlack";

Take a look at the webhook definition

Look at src/basicWebhook.js. As you can see, it's quite simple and just has a name and a title.

import { defineWebhook } from "@runlightyear/lightyear";
 
const basicWebhook = defineWebhook({
  name: "basicWebhook",
  title: "Basic Webhook",
});
 
export default basicWebhook;

Make it the trigger for an action

In src/helloSlack.js, first import basicWebhook and then add it as the trigger for the helloSlack action.

import { defineAction } from "@runlightyear/lightyear";
import { Slack } from "@runlightyear/slack";
import basicWebhook from "./basicWebhook";
 
defineAction({
  name: "helloSlack",
  title: "Hello Slack",
  description: "Send a message to Slack",
  apps: ["slack"],
  variables: ["channel"],
  trigger: {
    webhook: basicWebhook,
  },
  run: async ({ auths, variables }) => {
    const slack = new Slack({ auth: auths.slack });
 
    await slack.postMessage({
      channel: variables.channel,
      text: "Hello Slack!",
    });
 
    console.info("Posted message to Slack");
  },
});

Check out the updates

Select the Webhooks menu now see the newly created basicWebhook in Webhooks.

Lightyear Logo
Environment
Development
Apps
Actions
Webhooks
Runs
Deploys
Account
Docs
Webhooks
Basic Webhook
basicWebhook
Hello Slack
Slack Icon

Trigger the webhook

When you click on the basicWebhook card...

Lightyear Logo
Environment
Development
Apps
Actions
Webhooks
Runs
Deploys
Account
Docs
Webhooks
Basic Webhook
basicWebhook
Hello Slack
Slack Icon

...you can see the actual endpoint URL that was generated.

Lightyear Logo
Environment
Development
Apps
Actions
Webhooks
Runs
Deploys
Account
Docs
basicWebhook
Basic Webhook
Ready
http://app.runlightyear.com/api/v1/endpoints/f35bc5d9-9726-4b7d-a483-02c0c994b454
Config
Subscription
Deliveries
Config
Apps
No apps
Variables
No variables
Secrets
No secrets

Copy the URL and paste it into a new browser tab and you should see this:

{ "message": "Success" }

Returning to the dashboard, you can see the first webhook delivery that you just triggered.

Lightyear Logo
Environment
Development
Apps
Actions
Webhooks
Runs
Deploys
Account
Docs
basicWebhook
Basic Webhook
Ready
https://app.runlightyear.com/api/v1/endpoints/f35bc5d9-9726-4b7d-a483-02c0c994b454
Config
Subscription
Deliveries
Deliveries
Received at
Mar 29, 2023 5:48 AM
b37d5c4f-c4e0-42c1-9004-8f678847d4a0
Received at  
Mar 29, 2023 5:48 AM
b37d5c4f-c4e0-42c1-9004-8f678847d4a0
 [INFO]:
Received GET at /api/v1/endpoints/f35bc5d9-9726-4b7d-a483-02c0c994b454
 [INFO]:
Triggering run on action webhookSlack
 [INFO]:
Success

You should also see the message in Slack.