Skip to content

web-api: public canvas APIs#1813

Merged
filmaj merged 8 commits intomainfrom
web-api-public-canvas-apis
Jun 12, 2024
Merged

web-api: public canvas APIs#1813
filmaj merged 8 commits intomainfrom
web-api-public-canvas-apis

Conversation

@filmaj
Copy link
Copy Markdown
Contributor

@filmaj filmaj commented Jun 10, 2024

Adds several new Canvas APIs: create, edit, delete, sections.lookup, access.delete, access.set and conversations.canvases.create.

The response shapes were generated using slackapi/java-slack-sdk#1322

Manual Testing

To give this PR a try, check out this branch locally, then you can add a test.ts to the packages/web-api directory that is the following code. It exercises the various Canvas APIs: creates a canvas, sets access on it, looks up sections on it, edits it, and finally deletes it. You will need to export a SLACK_BOT_TOKEN environment variable before running it, that is a bot token with at least canvases:write, canvases:read and files:read scopes. This script code executes against the dev environment. Finally, make sure to adjust the channel and user IDs at the top of the script to match a channel and user ID in the workspace you are testing in.

You can run it with npx tsx test.ts:

import assert from 'assert';
import { WebClient, LogLevel } from './src/';
(async () => {
  const channel = 'C0147RBUF19';
  const user = 'U0147RBMVB5';
  const client = new WebClient(process.env.SLACK_BOT_TOKEN, {
    logLevel: LogLevel.DEBUG,
    slackApiUrl: 'https://dev.slack.com/api/',
  });
  const canvas = await client.canvases.create({"title":"new canvas" + new Date(), "document_content": {"type":"markdown","markdown":`
# Heading ONE

> And this is a quote

## HEading TWO

- list one
- list two
`}});
  console.log('create resp', canvas);
  const info = await client.files.info({
    file: canvas.canvas_id!,
  });
  const permalink = info.file?.permalink;
  await client.chat.postMessage({
    channel,
    text: `Here's the canvas I just created: ${permalink}`
  });
  console.log('canvases.access.set resp', await client.canvases.access.set({
    canvas_id: canvas.canvas_id!,
    access_level: 'write',
    channel_ids: [channel],
  }));
  console.log('canvases.access.set resp', await client.canvases.access.set({
    canvas_id: canvas.canvas_id!,
    access_level: 'write',
    user_ids: [user],
  }));
  console.log('canvases.access.delete resp', await client.canvases.access.delete({
    canvas_id: canvas.canvas_id!,
    user_ids: [user],
  }));
  console.log('canvases.access.delete resp', await client.canvases.access.delete({
    canvas_id: canvas.canvas_id!,
    channel_ids: [channel],
  }));
  const { sections } = await client.canvases.sections.lookup({
    canvas_id: canvas.canvas_id!,
    criteria: {
      contains_text: "list"
    }
  });
  const originalNumberOfListItems = sections!.length;
  console.log('canvases.edit resp', await client.canvases.edit({
    canvas_id: canvas.canvas_id!,
    changes: [
      {
        operation: 'insert_after',
        section_id: sections![0].id!,
        document_content: {
          type: 'markdown',
          markdown: `- a new list item appears!\n`
        }
      }
    ]
  }));
  const { sections: sectionsTwo } = await client.canvases.sections.lookup({
    canvas_id: canvas.canvas_id!,
    criteria: {
      contains_text: "list"
    }
  });
  assert.equal(sectionsTwo!.length, originalNumberOfListItems + 1, 'expected one more section retrieved from lookup that contain the word "list" than originally created')
  console.log('canvases.delete resp', await client.canvases.delete({
    canvas_id: canvas.canvas_id!,
  }));
})();

@filmaj filmaj added semver:minor enhancement M-T: A feature request for new functionality area:typescript issues that specifically impact using the package from typescript projects pkg:web-api applies to `@slack/web-api` labels Jun 10, 2024
@filmaj filmaj added this to the web-api@7.1.0 milestone Jun 10, 2024
@filmaj filmaj self-assigned this Jun 10, 2024
@codecov
Copy link
Copy Markdown

codecov bot commented Jun 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.76%. Comparing base (9f2935f) to head (e5022fc).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1813      +/-   ##
==========================================
+ Coverage   81.62%   81.76%   +0.13%     
==========================================
  Files          35       35              
  Lines        7684     7742      +58     
  Branches      316      316              
==========================================
+ Hits         6272     6330      +58     
  Misses       1400     1400              
  Partials       12       12              
Flag Coverage Δ
cli-hooks 95.07% <ø> (ø)
cli-test 53.80% <ø> (ø)
oauth 76.51% <ø> (ø)
socket-mode 59.41% <ø> (ø)
web-api 96.53% <100.00%> (+0.05%) ⬆️
webhook 95.20% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@filmaj filmaj requested a review from a team June 11, 2024 12:00
Copy link
Copy Markdown
Contributor

@srajiang srajiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tester script and instructs are much appreciated!

I think we could even start making a habit of sharing manifest setups to make getting configured for testing even smoother (ended up needing to add scopes). Here's mine:

manifest (6).json

This also forced me to update my terribly out of date node version to boot 🙇 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:typescript issues that specifically impact using the package from typescript projects enhancement M-T: A feature request for new functionality pkg:web-api applies to `@slack/web-api` semver:minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants