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

Replace all content of a canvas #1289

Open
sockeqwe opened this issue Apr 2, 2025 · 2 comments
Open

Replace all content of a canvas #1289

sockeqwe opened this issue Apr 2, 2025 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@sockeqwe
Copy link

sockeqwe commented Apr 2, 2025

Hello,
I think this is not really a bolt-python question but rather a general slack api question.

I would like to write a slack integration that periodically updates a canvas with updated business numbers. So kind of (mis)use canvas as some sort of simple "dashboard" for my team.

I see 2 options:

  1. Delete the previous canvas and create an entirely new one with the update content by using client.canvases_delete(canvas_id) and client.canvases_create(...)
  2. Use client.canvases_edit( canvas_id= canvas_id, changes= [...]) but for that it seems that I have to look up section id's of the content with client.canvases_sections_lookup(...). So I thought about getting the full content of the canvas with client.canvases_sections_lookup(...) and then do delete operations for each piece of content and the fill the empty canvas with the updated content with insert operations.

I prefer the option number 2 because then the same canvas instance is kept and update and can be marked as the one that should be opened as a secondary view when the slack channel is opened.

However, it looks like I cannot lookup other content type on the canvas apart from headers with client.canvases_sections_lookup(...). i.e. Could I delete a markdown table or paragraph or any simple text that is displayed inside the canvas somehow with your SDK? Do I miss anything?

@hello-ashleyintech hello-ashleyintech self-assigned this Apr 2, 2025
@hello-ashleyintech hello-ashleyintech added the question Further information is requested label Apr 2, 2025
@hello-ashleyintech
Copy link

Hi, @sockeqwe! thanks for your question 😄

I think #2 would be the best approach! You are correct that for the canvases.sections.lookup API it is currently limited to headers and header names. It seems like it will still pull the "section" however, so as long as a markdown table or paragraph is under that specific header section, it seems like it should be able to delete the whole section under the found header.

@sockeqwe
Copy link
Author

sockeqwe commented Apr 4, 2025

Thank you @hello-ashleyintech

Unfortunately it doesn't seem to work that deleting the headline also deletes something below it or maybe I set up the canvas content (I only tried markdown) somehow wrong.

I create a canvas like this:

content = """
# Headline 1
This is my canvas content

## Headline 2
this is the section 2 with a random int  
Some **bold** text

### Headline 3
Some _italic_ text
"""

response = await client.canvases_create(
            title= "Test Canvas",
            document_content={
                "type": "markdown",
                "markdown": content
            },
            channel_id=channel_id,
)

canvas_id = response["canvas_id"]

With the code above the canvas looks like this:
Image

Then I want to clear the content with the canvases_sections_lookup method with the following code:

sections_response = await client.canvases_sections_lookup(
            canvas_id=canvas_id,
            criteria={
                "section_types": ["any_header"]
            }
        )

print(sections_response)
sections = sections_response.get("sections", [])
for section in sections:
    print(section)
    change = {
        "operation": "delete",
        "section_id": f"{section.get('id')}",
    }

    response = await client.canvases_edit(
        canvas_id= canvas_id,
        changes= [change]
    )

The result of the code above is that only the headers are deleted from the canvas:

Image

Thanks again for your help, but looks like the current API is limiting to achieve what I want to achieve or is there another way to define content without markdown to create "sections" in another format so that deleting all sections could result in clearing the canvas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants