slackapi / deno-slack-sdk

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

Type file id with builtins #241

Closed WilliamBergamin closed 9 months ago

WilliamBergamin commented 9 months ago

Summary

This is a copy of #237 the feature release was pushed, I therefore reverted the changes in order to allow other contributions to main

This PR introduces the new slack type slack#/types/file_id and update the slack functions to use this new type.

Had to also modify he generation script to improve the robustness of the generated tests

testing

  1. Add https://raw.githubusercontent.com/slackapi/deno-slack-sdk/type_file_id_with_builtins/src/ as the value of deno-slack-sdk/ in the import_map.json of a project
  2. Build a workflow that uses the new feature example
import { DefineWorkflow, Schema } from "deno-slack-sdk/mod.ts";

const ImageWorkflow = DefineWorkflow({
  callback_id: "post_image",
  title: "Workflow to post an image",
  description: "A workflow that post an image in the channel it is invoked",
  input_parameters: {
    properties: {
      interactivity: {
        type: Schema.slack.types.interactivity
      },
      channel: {
        type: Schema.slack.types.channel_id,
      },
    },
    required: ["channel", "interactivity"],
  },
});

const getImageStep = ImageWorkflow.addStep(
  Schema.slack.functions.OpenForm,
  {
    title: "Submit this form",
    interactivity: ImageWorkflow.inputs.interactivity,
    fields:{
      elements: [{
        title: "Enter a file",
        name: "image",
        type: Schema.types.array,
        maxItems: 1,
        items: {
          type: Schema.slack.types.file_id,
        },
      }],
      required: ["image"],
    }
  },
);

ImageWorkflow.addStep(Schema.slack.functions.SendMessage, {
  channel_id: ImageWorkflow.inputs.channel,
  message: "cool image bro",
  files: getImageStep.outputs.fields.image
});

export default ImageWorkflow;
  1. Everything should run as expected

Special notes

Ensure your app has the files:read scope, since this is required for the feature and logged error is cryptic

Requirements

codecov[bot] commented 9 months ago

Codecov Report

Merging #241 (e47e6ba) into main (b160668) will increase coverage by 0.08%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #241      +/-   ##
==========================================
+ Coverage   97.98%   98.07%   +0.08%     
==========================================
  Files          58       58              
  Lines        2182     2280      +98     
  Branches      137      137              
==========================================
+ Hits         2138     2236      +98     
  Misses         42       42              
  Partials        2        2              
Files Coverage Δ
src/dev_deps.ts 100.00% <100.00%> (ø)
src/schema/slack/functions/add_pin.ts 100.00% <100.00%> (ø)
...rc/schema/slack/functions/add_user_to_usergroup.ts 100.00% <100.00%> (ø)
src/schema/slack/functions/archive_channel.ts 100.00% <ø> (ø)
src/schema/slack/functions/create_channel.ts 100.00% <ø> (ø)
src/schema/slack/functions/create_usergroup.ts 100.00% <100.00%> (ø)
src/schema/slack/functions/delay.ts 100.00% <100.00%> (ø)
...c/schema/slack/functions/invite_user_to_channel.ts 100.00% <100.00%> (ø)
src/schema/slack/functions/mod.ts 100.00% <100.00%> (ø)
src/schema/slack/functions/open_form.ts 100.00% <100.00%> (ø)
... and 7 more

:mega: Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!