Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: New built-in step Add Canvas to Channel Tab, changes to function generation #367

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/schema/slack/functions/_scripts/src/templates/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ import { AllowedTypeValue, AllowedTypeValueObject } from "./types.ts";
import { isCustomType } from "../../../../../../types/mod.ts";
import { isArrayFunctionProperty, isObjectFunctionProperty } from "../utils.ts";

// For coded workflow backwards compatibility, we alias certain builtins to their old names.
const ID_ALIASES: Record<string, string> = {
"canvas_update_content_v2": "canvas_update_content",
};

function useIdAlias(callback_id: string): string {
return callback_id in ID_ALIASES ? ID_ALIASES[callback_id] : callback_id;
}

export function autogeneratedComment(includeDate?: boolean): string {
const dateString = includeDate ? ` on ${new Date().toDateString()}` : "";
return `/** This file was autogenerated${dateString}. Follow the steps in src/schema/slack/functions/_scripts/README.md to rebuild **/`;
Expand All @@ -17,7 +26,7 @@ export function renderFunctionImport(callbackId: string): string {
}

export function getFunctionName(callbackId: string): string {
return pascalCase(callbackId);
return pascalCase(useIdAlias(callbackId));
}

export function getSlackCallbackId(
Expand Down
4 changes: 3 additions & 1 deletion src/schema/slack/functions/_scripts/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ export const greenText = (text: string) => green + text + reset;
export const yellowText = (text: string) => yellow + text + reset;
export const redText = (text: string) => red + text + reset;

// TODO: once List steps work in code, bring this back
const FUNCTIONS_TO_IGNORE = [
// TODO: once List steps work in code, bring this back
"update_list_record",
"share_list_users",
"lists_activity_feed",
"list_add_record",
"delete_list_record",
"copy_list",
// canvas_update_content functionality got moved to canvas_update_content_v2
"canvas_update_content",
];

export async function getSlackFunctions(
Expand Down
45 changes: 45 additions & 0 deletions src/schema/slack/functions/add_canvas_to_channel_tab.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/** This file was autogenerated. Follow the steps in src/schema/slack/functions/_scripts/README.md to rebuild **/
import { DefineFunction } from "../../../functions/mod.ts";
import SchemaTypes from "../../schema_types.ts";
import SlackTypes from "../schema_types.ts";

export default DefineFunction({
callback_id: "slack#/functions/add_canvas_to_channel_tab",
source_file: "",
title: "Add a canvas to channel tab",
input_parameters: {
properties: {
label: {
type: SchemaTypes.string,
description: "Enter a tab label",
title: "Tab label",
},
channel_id: {
type: SlackTypes.channel_id,
description: "Channel name",
title: "Select a channel",
},
canvas_id: {
type: SlackTypes.canvas_id,
description: "Search all canvases",
title: "Select a canvas to add as a tab",
},
},
required: ["channel_id", "canvas_id"],
},
output_parameters: {
properties: {
canvas_id: {
type: SlackTypes.canvas_id,
description: "Canvas link",
title: "Canvas link",
},
channel_id: {
type: SlackTypes.channel_id,
description: "Channel name",
title: "Channel name",
},
},
required: ["canvas_id", "channel_id"],
},
});
93 changes: 93 additions & 0 deletions src/schema/slack/functions/add_canvas_to_channel_tab_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/** This file was autogenerated. Follow the steps in src/schema/slack/functions/_scripts/README.md to rebuild **/
import {
assertEquals,
assertExists,
assertNotStrictEquals,
} from "../../../dev_deps.ts";
import { DefineWorkflow } from "../../../workflows/mod.ts";
import { ManifestFunctionSchema } from "../../../manifest/manifest_schema.ts";
import SchemaTypes from "../../schema_types.ts";
import SlackTypes from "../schema_types.ts";
import AddCanvasToChannelTab from "./add_canvas_to_channel_tab.ts";

Deno.test("AddCanvasToChannelTab generates valid FunctionManifest", () => {
assertEquals(
AddCanvasToChannelTab.definition.callback_id,
"slack#/functions/add_canvas_to_channel_tab",
);
const expected: ManifestFunctionSchema = {
source_file: "",
title: "Add a canvas to channel tab",
input_parameters: {
properties: {
label: {
type: SchemaTypes.string,
description: "Enter a tab label",
title: "Tab label",
},
channel_id: {
type: SlackTypes.channel_id,
description: "Channel name",
title: "Select a channel",
},
canvas_id: {
type: SlackTypes.canvas_id,
description: "Search all canvases",
title: "Select a canvas to add as a tab",
},
},
required: ["channel_id", "canvas_id"],
},
output_parameters: {
properties: {
canvas_id: {
type: SlackTypes.canvas_id,
description: "Canvas link",
title: "Canvas link",
},
channel_id: {
type: SlackTypes.channel_id,
description: "Channel name",
title: "Channel name",
},
},
required: ["canvas_id", "channel_id"],
},
};
const actual = AddCanvasToChannelTab.export();

assertNotStrictEquals(actual, expected);
});

Deno.test("AddCanvasToChannelTab can be used as a Slack function in a workflow step", () => {
const testWorkflow = DefineWorkflow({
callback_id: "test_AddCanvasToChannelTab_slack_function",
title: "Test AddCanvasToChannelTab",
description: "This is a generated test to test AddCanvasToChannelTab",
});
testWorkflow.addStep(AddCanvasToChannelTab, {
channel_id: "test",
canvas_id: "test",
});
const actual = testWorkflow.steps[0].export();

assertEquals(
actual.function_id,
"slack#/functions/add_canvas_to_channel_tab",
);
assertEquals(actual.inputs, { channel_id: "test", canvas_id: "test" });
});

Deno.test("All outputs of Slack function AddCanvasToChannelTab should exist", () => {
const testWorkflow = DefineWorkflow({
callback_id: "test_AddCanvasToChannelTab_slack_function",
title: "Test AddCanvasToChannelTab",
description: "This is a generated test to test AddCanvasToChannelTab",
});
const step = testWorkflow.addStep(AddCanvasToChannelTab, {
channel_id: "test",
canvas_id: "test",
});
assertExists(step.outputs.canvas_id);
assertExists(step.outputs.channel_id);
});
7 changes: 6 additions & 1 deletion src/schema/slack/functions/canvas_create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ export default DefineFunction({
description: "Canvas link",
title: "Canvas link",
},
title: {
type: SchemaTypes.string,
description: "Canvas title",
title: "Canvas title",
},
},
required: ["canvas_id"],
required: ["canvas_id", "title"],
},
});
8 changes: 7 additions & 1 deletion src/schema/slack/functions/canvas_create_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ Deno.test("CanvasCreate generates valid FunctionManifest", () => {
description: "Canvas link",
title: "Canvas link",
},
title: {
type: SchemaTypes.string,
description: "Canvas title",
title: "Canvas title",
},
},
required: ["canvas_id"],
required: ["canvas_id", "title"],
},
};
const actual = CanvasCreate.export();
Expand Down Expand Up @@ -93,4 +98,5 @@ Deno.test("All outputs of Slack function CanvasCreate should exist", () => {
owner_id: "test",
});
assertExists(step.outputs.canvas_id);
assertExists(step.outputs.title);
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SchemaTypes from "../../schema_types.ts";
import SlackTypes from "../schema_types.ts";

export default DefineFunction({
callback_id: "slack#/functions/canvas_update_content",
callback_id: "slack#/functions/canvas_update_content_v2",
source_file: "",
title: "Update a canvas",
input_parameters: {
Expand All @@ -24,11 +24,21 @@ export default DefineFunction({
description: "Search standalone canvases",
title: "Select a canvas",
},
canvas_tab: {
type: SchemaTypes.string,
description: "Select an option",
title: "Choose which canvas to update",
},
section_id: {
type: SchemaTypes.string,
description: "Select an option",
title: "Choose which section to update",
},
canvas_tab_section_id: {
type: SchemaTypes.string,
description: "Select an option",
title: "Choose which section to update",
},
action: {
type: SchemaTypes.string,
description: "Select an option",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { DefineWorkflow } from "../../../workflows/mod.ts";
import { ManifestFunctionSchema } from "../../../manifest/manifest_schema.ts";
import SchemaTypes from "../../schema_types.ts";
import SlackTypes from "../schema_types.ts";
import CanvasUpdateContent from "./canvas_update_content.ts";
import CanvasUpdateContent from "./canvas_update_content_v2.ts";

Deno.test("CanvasUpdateContent generates valid FunctionManifest", () => {
assertEquals(
CanvasUpdateContent.definition.callback_id,
"slack#/functions/canvas_update_content",
"slack#/functions/canvas_update_content_v2",
);
const expected: ManifestFunctionSchema = {
source_file: "",
Expand All @@ -35,11 +35,21 @@ Deno.test("CanvasUpdateContent generates valid FunctionManifest", () => {
description: "Search standalone canvases",
title: "Select a canvas",
},
canvas_tab: {
type: SchemaTypes.string,
description: "Select an option",
title: "Choose which canvas to update",
},
section_id: {
type: SchemaTypes.string,
description: "Select an option",
title: "Choose which section to update",
},
canvas_tab_section_id: {
type: SchemaTypes.string,
description: "Select an option",
title: "Choose which section to update",
},
action: {
type: SchemaTypes.string,
description: "Select an option",
Expand Down Expand Up @@ -81,7 +91,7 @@ Deno.test("CanvasUpdateContent can be used as a Slack function in a workflow ste
});
const actual = testWorkflow.steps[0].export();

assertEquals(actual.function_id, "slack#/functions/canvas_update_content");
assertEquals(actual.function_id, "slack#/functions/canvas_update_content_v2");
assertEquals(actual.inputs, { action: "test", content: "test" });
});

Expand Down
5 changes: 5 additions & 0 deletions src/schema/slack/functions/channel_canvas_create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export default DefineFunction({
description: "Channel name",
title: "Select a channel",
},
title: {
type: SchemaTypes.string,
description: "Enter a canvas name",
title: "Canvas name",
},
canvas_create_type: {
type: SchemaTypes.string,
description: "Type of creation",
Expand Down
5 changes: 5 additions & 0 deletions src/schema/slack/functions/channel_canvas_create_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ Deno.test("ChannelCanvasCreate generates valid FunctionManifest", () => {
description: "Channel name",
title: "Select a channel",
},
title: {
type: SchemaTypes.string,
description: "Enter a canvas name",
title: "Canvas name",
},
canvas_create_type: {
type: SchemaTypes.string,
description: "Type of creation",
Expand Down
6 changes: 4 additions & 2 deletions src/schema/slack/functions/mod.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/** This file was autogenerated on Fri Sep 06 2024. Follow the steps in src/schema/slack/functions/_scripts/README.md to rebuild **/
/** This file was autogenerated on Tue Oct 08 2024. Follow the steps in src/schema/slack/functions/_scripts/README.md to rebuild **/
import AddBookmark from "./add_bookmark.ts";
import AddCanvasToChannelTab from "./add_canvas_to_channel_tab.ts";
import AddPin from "./add_pin.ts";
import AddReaction from "./add_reaction.ts";
import AddUserToUsergroup from "./add_user_to_usergroup.ts";
import ArchiveChannel from "./archive_channel.ts";
import CanvasCopy from "./canvas_copy.ts";
import CanvasCreate from "./canvas_create.ts";
import CanvasUpdateContent from "./canvas_update_content.ts";
import CanvasUpdateContent from "./canvas_update_content_v2.ts";
import ChannelCanvasCreate from "./channel_canvas_create.ts";
import CreateChannel from "./create_channel.ts";
import CreateUsergroup from "./create_usergroup.ts";
Expand All @@ -25,6 +26,7 @@ import UpdateChannelTopic from "./update_channel_topic.ts";

const SlackFunctions = {
AddBookmark,
AddCanvasToChannelTab,
AddPin,
AddReaction,
AddUserToUsergroup,
Expand Down