slackapi / deno-slack-sdk

SDK for building Run on Slack apps using Deno
https://api.slack.com/automation
151 stars 27 forks source link

Add canvas header section and variables fetcher to deno-sdk #294

Closed rafaelamsili closed 3 months ago

rafaelamsili commented 3 months ago

Summary

In order to be able to fully interact with the canvas workflow functions we need to expose the CanvasFetchHeaderSection and CanvasFetchVariables so developers can fetch the header sections and canvas variables and passed to the other built in functions

Testing

Created a demo app with the following

function

export const def = DefineFunction({
  callback_id: "choose_canvas_section",
  title: "Choose the second header section",
  source_file: "/functions/choose_canvas_section.ts",
  input_parameters: {
    properties: {
      sections: {
        type: Schema.types.array,
        description: "Sections",
        title: "Sections",
        items: { type: Schema.types.object },
      },
    },
    required: [],
  },
  output_parameters: {
    properties: { section: { type: Schema.types.string } },
    required: ["section"],
  },
});

export default SlackFunction(def, ({ inputs }) => {
  const sections = inputs.sections;
  if (!sections) {
    return {
      outputs: { section: undefined },
    };
  }
  return {
    outputs: { section: sections.length > 1 ? sections[1]["id"] : undefined },
  };

Workflow

const canvasId = "F015Y8QHX9Q";
const CanvasWorkflow = DefineWorkflow({
  callback_id: "canvas_workflow",
  title: "Create, Update and Share canvas",
  description: "Create, Update and Share canvas",
  input_parameters: {
    properties: {
      channel: {
        type: Schema.slack.types.channel_id,
      },
      user: {
        type: Schema.slack.types.user_id,
      },
    },
    required: ["channel"],
  },
});

const canvasFetchHeaderSections = CanvasWorkflow.addStep(
  Schema.slack.functions.CanvasFetchHeaderSections,
  {
    canvas_id: canvasId,
  },
);

const canvasSecondSection = CanvasWorkflow.addStep(ChooseCanvasSection, {
  sections: canvasFetchHeaderSections.outputs.sections,
});

const updateCanvasStep = CanvasWorkflow.addStep(
  Schema.slack.functions.CanvasUpdateContent,
  {
    canvas_id: canvasId,
    section_id: canvasSecondSection.outputs.section,
    action: "append",
    content: [
      {
        "type": "rich_text",
        "elements": [
          {
            "type": "rich_text_section",
            "elements": [{
              "type": "text",
              "text": "Updating second header section",
            }],
          },
        ],
      },
    ],
  },
);

Special notes

Requirements

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 98.39%. Comparing base (de2ca5c) to head (26756df).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #294 +/- ## ========================================== + Coverage 98.35% 98.39% +0.04% ========================================== Files 63 65 +2 Lines 2552 2623 +71 Branches 147 147 ========================================== + Hits 2510 2581 +71 Misses 42 42 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

filmaj commented 3 months ago

I believe this functionality still needs backend support, so am closing this PR until it is available in production.