Skip to content

Commit

Permalink
Add new Canvas built in functions to the deno-sdk (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelamsili authored Feb 29, 2024
1 parent 9de72ce commit 8563f41
Show file tree
Hide file tree
Showing 13 changed files with 762 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/functions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ type FunctionInputRuntimeType<
| typeof SlackSchemaTypes.user_id
| typeof SlackSchemaTypes.usergroup_id
| typeof SlackSchemaTypes.channel_id
| typeof SlackSchemaTypes.canvas_id
| typeof SlackSchemaTypes.canvas_template_id
| typeof SlackSchemaTypes.date
| typeof SlackSchemaTypes.message_ts ? string
: Param["type"] extends
Expand All @@ -96,6 +98,8 @@ type FunctionInputRuntimeType<
: UnknownRuntimeType
: Param["type"] extends typeof SlackSchemaTypes.rich_text
? UnknownRuntimeType
: Param["type"] extends typeof SlackSchemaTypes.expanded_rich_text
? UnknownRuntimeType
: UnknownRuntimeType;

// deno-lint-ignore no-explicit-any
Expand Down
46 changes: 46 additions & 0 deletions src/schema/slack/functions/canvas_copy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/** 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 { SlackPrimitiveTypes } from "../../slack/types/mod.ts";
import SlackTypes from "../schema_types.ts";

export default DefineFunction({
callback_id: "slack#/functions/canvas_copy",
source_file: "",
title: "Copy a canvas",
input_parameters: {
properties: {
canvas_id: {
type: SlackPrimitiveTypes.canvas_id,
description: "Search all canvases",
title: "Select a canvas",
},
title: {
type: SchemaTypes.string,
description: "Enter a canvas name",
title: "Canvas name",
},
owner_id: {
type: SlackTypes.user_id,
description: "Canvas owner id",
title: "Owner",
},
placeholder_values: {
type: SchemaTypes.object,
description: "Variables",
title: "Variables",
},
},
required: ["canvas_id", "title", "owner_id"],
},
output_parameters: {
properties: {
canvas_id: {
type: SlackPrimitiveTypes.canvas_id,
description: "Canvas link",
title: "Canvas link",
},
},
required: ["canvas_id"],
},
});
97 changes: 97 additions & 0 deletions src/schema/slack/functions/canvas_copy_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/** 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 { SlackPrimitiveTypes } from "../../slack/types/mod.ts";

import CanvasCopy from "./canvas_copy.ts";

Deno.test("CanvasCopy generates valid FunctionManifest", () => {
assertEquals(
CanvasCopy.definition.callback_id,
"slack#/functions/canvas_copy",
);
const expected: ManifestFunctionSchema = {
source_file: "",
title: "Copy a canvas",
input_parameters: {
properties: {
canvas_id: {
type: SlackPrimitiveTypes.canvas_id,
description: "Search all canvases",
title: "Select a canvas",
},
title: {
type: SchemaTypes.string,
description: "Enter a canvas name",
title: "Canvas name",
},
owner_id: {
type: SlackTypes.user_id,
description: "Canvas owner id",
title: "Owner",
},
placeholder_values: {
type: SchemaTypes.object,
description: "Variables",
title: "Variables",
},
},
required: ["canvas_id", "title", "owner_id"],
},
output_parameters: {
properties: {
canvas_id: {
type: SlackPrimitiveTypes.canvas_id,
description: "Canvas link",
title: "Canvas link",
},
},
required: ["canvas_id"],
},
};
const actual = CanvasCopy.export();

assertNotStrictEquals(actual, expected);
});

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

assertEquals(actual.function_id, "slack#/functions/canvas_copy");
assertEquals(actual.inputs, {
canvas_id: "test",
title: "test",
owner_id: "test",
});
});

Deno.test("All outputs of Slack function CanvasCopy should exist", () => {
const testWorkflow = DefineWorkflow({
callback_id: "test_CanvasCopy_slack_function",
title: "Test CanvasCopy",
description: "This is a generated test to test CanvasCopy",
});
const step = testWorkflow.addStep(CanvasCopy, {
canvas_id: "test",
title: "test",
owner_id: "test",
});
assertExists(step.outputs.canvas_id);
});
56 changes: 56 additions & 0 deletions src/schema/slack/functions/canvas_create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/** 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 { SlackPrimitiveTypes } from "../../slack/types/mod.ts";
import SlackTypes from "../schema_types.ts";

export default DefineFunction({
callback_id: "slack#/functions/canvas_create",
source_file: "",
title: "Create a canvas",
input_parameters: {
properties: {
title: {
type: SchemaTypes.string,
description: "Enter a canvas name",
title: "Canvas name",
},
canvas_create_type: {
type: SchemaTypes.string,
description: "Type of creation",
title: "Type of creation",
},
canvas_template_id: {
type: SlackPrimitiveTypes.canvas_template_id,
description: "Select an option",
title: "Select a canvas template",
},
owner_id: {
type: SlackTypes.user_id,
description: "Person",
title: "Canvas owner",
},
content: {
type: SlackPrimitiveTypes.expanded_rich_text,
description: "Add content to the canvas",
title: "Add content",
},
placeholder_values: {
type: SchemaTypes.object,
description: "Variables",
title: "Variables",
},
},
required: ["title", "owner_id"],
},
output_parameters: {
properties: {
canvas_id: {
type: SlackPrimitiveTypes.canvas_id,
description: "Canvas link",
title: "Canvas link",
},
},
required: ["canvas_id"],
},
});
97 changes: 97 additions & 0 deletions src/schema/slack/functions/canvas_create_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/** 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 { SlackPrimitiveTypes } from "../../slack/types/mod.ts";
import CanvasCreate from "./canvas_create.ts";

Deno.test("CanvasCreate generates valid FunctionManifest", () => {
assertEquals(
CanvasCreate.definition.callback_id,
"slack#/functions/canvas_create",
);
const expected: ManifestFunctionSchema = {
source_file: "",
title: "Create a canvas",
input_parameters: {
properties: {
title: {
type: SchemaTypes.string,
description: "Enter a canvas name",
title: "Canvas name",
},
canvas_create_type: {
type: SchemaTypes.string,
description: "Type of creation",
title: "Type of creation",
},
canvas_template_id: {
type: SlackPrimitiveTypes.canvas_template_id,
description: "Select an option",
title: "Select a canvas template",
},
owner_id: {
type: SlackTypes.user_id,
description: "Person",
title: "Canvas owner",
},
content: {
type: SlackPrimitiveTypes.expanded_rich_text,
description: "Add content to the canvas",
title: "Add content",
},
placeholder_values: {
type: SchemaTypes.object,
description: "Variables",
title: "Variables",
},
},
required: ["title", "owner_id"],
},
output_parameters: {
properties: {
canvas_id: {
type: SlackPrimitiveTypes.canvas_id,
description: "Canvas link",
title: "Canvas link",
},
},
required: ["canvas_id"],
},
};
const actual = CanvasCreate.export();

assertNotStrictEquals(actual, expected);
});

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

assertEquals(actual.function_id, "slack#/functions/canvas_create");
assertEquals(actual.inputs, { title: "test", owner_id: "test" });
});

Deno.test("All outputs of Slack function CanvasCreate should exist", () => {
const testWorkflow = DefineWorkflow({
callback_id: "test_CanvasCreate_slack_function",
title: "Test CanvasCreate",
description: "This is a generated test to test CanvasCreate",
});
const step = testWorkflow.addStep(CanvasCreate, {
title: "test",
owner_id: "test",
});
assertExists(step.outputs.canvas_id);
});
56 changes: 56 additions & 0 deletions src/schema/slack/functions/canvas_update_content.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/** 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 { SlackPrimitiveTypes } from "../../slack/types/mod.ts";
import SlackTypes from "../schema_types.ts";

export default DefineFunction({
callback_id: "slack#/functions/canvas_update_content",
source_file: "",
title: "Update a canvas",
input_parameters: {
properties: {
canvas_update_type: {
type: SchemaTypes.string,
description: "Type of update",
title: "Type of update",
},
channel_id: {
type: SlackTypes.channel_id,
description: "Channel name",
title: "Select a channel",
},
canvas_id: {
type: SlackPrimitiveTypes.canvas_id,
description: "Search standalone canvases",
title: "Select a canvas",
},
section_id: {
type: SchemaTypes.string,
description: "Select an option",
title: "Choose which section to update",
},
action: {
type: SchemaTypes.string,
description: "Select an option",
title: "How do you want to update?",
},
content: {
type: SlackPrimitiveTypes.expanded_rich_text,
description: "Add content to the canvas",
title: "Content",
},
},
required: ["action", "content"],
},
output_parameters: {
properties: {
canvas_id: {
type: SlackPrimitiveTypes.canvas_id,
description: "Canvas link",
title: "Canvas link",
},
},
required: ["canvas_id"],
},
});
Loading

0 comments on commit 8563f41

Please sign in to comment.