1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { slackrespond } from "https://esm.town/v/nate/slackrespond";
import process from "node:process";
// A Slack slash command app to evaluate a val.town expression.
//
// Setup: Add a slash command using
// "https://api.val.town/express/@nate.slackapp" as the request URL.
//
// Usage: /yourcommandname {expression}
//
// Examples:
// - /evaltown 1+1
// - /evaltown @nate.email("Hi from Slack!")
export let slackapp = async (req, res) => {
if ("ssl_check" in req.body) return;
if (
!("api_app_id" in req.body) ||
req.body.api_app_id !== process.env.SLACK_API_APP_ID ||
!("text" in req.body) ||
!("response_url" in req.body)
) {
res.status(200);
res.set("Content-Type", "application/json");
res.send(
JSON.stringify({
text: "A parameter was invalid or missing.",
})
);
return;
}
// Slack requires a response within 3 seconds so we send back an empty
// response as an acknowledgment and process the request asynchronously.
res.status(200).send();
await slackrespond(req.body.response_url, req.body.text);
};
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.