Step 5 - Configure a Variable
In the last step, we were able to hard-code the channel for the Slack message. But if you want the channel to be configurable outside of the code, you can use a variable.
Add a variable to the helloSlack
action
Change the following 3 lines in src/helloSlack.js
:
import { defineAction } from "@runlightyear/lightyear";
import { Slack } from "@runlightyear/slack";
defineAction({
name: "helloSlack",
title: "Hello Slack",
description: "Send a message to Slack",
apps: ["slack"],
variables: ["channel"],
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");
},
});
Enter a value for the new variable
Go back to the Config
tab and enter a value for the new channel variable.
Environment
Development
Apps
Actions
Webhooks
Runs
Deploys
Account
Docs
helloSlack
Hello Slack
Ready
Config
Runs
Config
Apps
Slack
Authorized
Variables
Name
Value
channel *
Secrets
No secrets
Once you have saved that, click Trigger
again.
Environment
Development
Apps
Actions
Webhooks
Runs
Deploys
Account
Docs
helloSlack
Hello Slack
Ready
Config
Runs
Config
Apps
Slack
Authorized
Variables
Name
Value
channel *
Secrets
No secrets
You should see the message posted in that Slack channel.