Skip to content
This repository was archived by the owner on Dec 9, 2022. It is now read-only.

Commit f46c8ae

Browse files
committed
Update
1 parent 4c9832e commit f46c8ae

File tree

4 files changed

+20
-21
lines changed

4 files changed

+20
-21
lines changed

functions/setup.ts

+17-18
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import { SlackAPI } from "deno-slack-api/mod.ts";
33
import { Logger } from "../utils/logger.ts";
44
import { FunctionSourceFile } from "../utils/function_source_file.ts";
55

6-
/**
7-
* See https://api.slack.com/future/functions/custom
8-
*/
96
export const def = DefineFunction({
107
callback_id: "manage-reaction-added-event-trigger",
118
title: "Manage a reaction_added event trigger",
@@ -28,12 +25,11 @@ export default SlackFunction(def, async ({
2825
env,
2926
token,
3027
}) => {
31-
const logger = Logger(env.logLevel);
32-
logger.debug(inputs);
28+
const logger = Logger(env.LOG_LEVEL);
3329

3430
const client = SlackAPI(token);
31+
// Check the existing triggers for this workflow
3532
const allTriggers = await client.workflows.triggers.list({});
36-
logger.info(allTriggers);
3733
let triggerToUpdate = undefined;
3834
// find the trigger to update
3935
if (allTriggers.triggers) {
@@ -46,9 +42,13 @@ export default SlackFunction(def, async ({
4642
}
4743
}
4844
}
45+
logger.info(`triggerToUpdate: ${JSON.stringify(triggerToUpdate)}`);
46+
4947
const channelIds = triggerToUpdate?.channel_ids != undefined
5048
? triggerToUpdate.channel_ids
5149
: [];
50+
51+
// Open the modal to configure the channel list to enable this workflow
5252
await client.views.open({
5353
interactivity_pointer: inputs.interactivity.interactivity_pointer,
5454
view: {
@@ -91,19 +91,13 @@ export default SlackFunction(def, async ({
9191
.addViewSubmissionHandler(
9292
["configure-workflow"],
9393
async ({ view, inputs, env, token }) => {
94-
const logger = Logger(env.logLevel);
94+
const logger = Logger(env.LOG_LEVEL);
9595
const { workflowCallbackId } = inputs;
9696
const channelIds = view.state.values.block.channels.selected_channels;
9797
const triggerInputs = {
98-
channelId: {
99-
value: "{{data.channel_id}}",
100-
},
101-
messageTs: {
102-
value: "{{data.message_ts}}",
103-
},
104-
reaction: {
105-
value: "{{data.reaction}}",
106-
},
98+
channelId: { value: "{{data.channel_id}}" },
99+
messageTs: { value: "{{data.message_ts}}" },
100+
reaction: { value: "{{data.reaction}}" },
107101
};
108102

109103
const client = SlackAPI(token);
@@ -125,6 +119,7 @@ export default SlackFunction(def, async ({
125119
}
126120

127121
if (triggerToUpdate === undefined) {
122+
// Create a new trigger
128123
const creation = await client.workflows.triggers.create({
129124
type: "event",
130125
name: "reaction_added event trigger",
@@ -137,6 +132,7 @@ export default SlackFunction(def, async ({
137132
});
138133
logger.info(`A new trigger created: ${JSON.stringify(creation)}`);
139134
} else {
135+
// Update the existing trigger
140136
const update = await client.workflows.triggers.update({
141137
trigger_id: triggerToUpdate.id,
142138
type: "event",
@@ -150,6 +146,9 @@ export default SlackFunction(def, async ({
150146
});
151147
logger.info(`A new trigger updated: ${JSON.stringify(update)}`);
152148
}
149+
150+
// This app's bot user joins all the channels
151+
// to perform API calls for the channels
153152
for (const channelId of channelIds) {
154153
const joinResult = await client.conversations.join({
155154
channel: channelId,
@@ -191,8 +190,8 @@ export default SlackFunction(def, async ({
191190
.addViewClosedHandler(
192191
["configure-workflow"],
193192
({ view, env }) => {
194-
const logger = Logger(env.logLevel);
195-
logger.debug(JSON.stringify(view, null, 2));
193+
const logger = Logger(env.LOG_LEVEL);
194+
logger.debug(JSON.stringify(view));
196195
return {
197196
outputs: {},
198197
completed: true,

manifest.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import reacjilator from "./workflows/reacjilator.ts";
33
import setup from "./workflows/setup.ts";
44

55
export default Manifest({
6-
name: "DeepL for Slack",
6+
name: "DeepL for Slack (beta)",
77
description: "A beta app that enbales using DeepL for Slack messages",
88
icon: "assets/icon.png",
99
workflows: [

workflows/reacjilator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { def as translatorDef } from "../functions/translator.ts";
44

55
const workflow = DefineWorkflow({
66
callback_id: "reacjilator",
7-
title: "DeepL translation",
7+
title: "DeepL translation (beta)",
88
description: "Translate a message when a flag reaction is added",
99
input_parameters: {
1010
properties: {

workflows/setup.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { default as reacjilatorDef } from "./reacjilator.ts";
77
*/
88
const workflow = DefineWorkflow({
99
callback_id: "reacjilator-setup",
10-
title: "Configure DeepL translator app in channels",
10+
title: "Configure DeepL translator app in channels (beta)",
1111
input_parameters: {
1212
properties: {
1313
interactivity: { type: Schema.slack.types.interactivity },

0 commit comments

Comments
 (0)