Step 5 - 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",
apps: ["slack"],
trigger: {
webhook: basicWebhook,
},
run: async ({ auths }) => {
const slack = new Slack({ auth: auths.slack });
await slack.postMessage({
channel: "#general", // <-- you might want to change this!
text: "Hello Slack!",
});
console.info("Posted message to Slack");
},
});
Let's also change the text
to reflect that we triggered from a webhook.
import { defineAction } from "@runlightyear/lightyear";
import { Slack } from "@runlightyear/slack";
import basicWebhook from "./basicWebhook";
defineAction({
name: "helloSlack",
title: "Hello Slack",
apps: ["slack"],
trigger: {
webhook: basicWebhook,
},
run: async ({ auths }) => {
const slack = new Slack({ auth: auths.slack });
await slack.postMessage({
channel: "#general", // <-- you might want to change this!
text: "Hello from a webhook!",
});
console.info("Posted message to Slack");
},
});
Check out the updates
Select the Webhooks
menu now see the newly created basicWebhook
in Webhooks
.
0
Trigger the webhook
When you click on the basicWebhook
card...
0
...you can see the actual endpoint URL that was generated.
0
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.
0
You should also see the message in Slack.