generated from slack-samples/deno-starter-template
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathgreeting_function.ts
49 lines (47 loc) · 1.47 KB
/
greeting_function.ts
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
39
40
41
42
43
44
45
46
47
48
49
import { DefineFunction, Schema, SlackFunction } from "deno-slack-sdk/mod.ts";
/**
* Functions are reusable building blocks of automation that accept
* inputs, perform calculations, and provide outputs. Functions can
* be used independently or as steps in workflows.
* https://api.slack.com/automation/functions/custom
*/
export const GreetingFunctionDefinition = DefineFunction({
callback_id: "greeting_function",
title: "Generate a greeting",
description: "Generate a greeting",
source_file: "functions/greeting_function.ts",
input_parameters: {
properties: {
recipient: {
type: Schema.slack.types.user_id,
description: "Greeting recipient",
},
message: {
type: Schema.types.string,
description: "Message to the recipient",
},
},
required: ["message", "recipient"],
},
output_parameters: {
properties: {
greeting: {
type: Schema.types.string,
description: "Greeting for the recipient",
},
},
required: ["greeting"],
},
});
export default SlackFunction(
GreetingFunctionDefinition,
({ inputs }) => {
const { recipient, message } = inputs;
const salutations = ["Hello", "Hi", "Howdy", "Hola", "Salut"];
const salutation =
salutations[Math.floor(Math.random() * salutations.length)];
const greeting =
`${salutation}, <@${recipient}>! :wave: Someone sent the following greeting: \n\n>${message}`;
return { outputs: { greeting } };
},
);