slackapi / bolt-python

A framework to build Slack apps using Python

Home Page:https://slack.dev/bolt-python/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue with Submitting Slack App Modal when 'user' Element is Included in Initial Value

lancewl opened this issue · comments

Hello,

I'm currently working on a Slack app that features a rich_text_input within a modal, allowing users to input content and submit it. While I've successfully handled various types of styling content submissions, I've encountered an issue when a user element ({'type': 'user', 'user_id': 'UXXXXXX'}) is included in the initial_value.

The problem arises when the modal fails to submit the view to the backend, providing a vague error message: "We had some trouble connecting. Try again?" Despite having a correctly set up handler on the backend for processing submissions with other styling, in this particular case, the modal fails without triggering the event handler. This leads me to suspect an internal issue with how Slack handles the initial_values.

Notably, I observed that the issue seems to resolve if users type anything in the rich_text_input area before submitting. I speculate that the UI may refresh during user typing, potentially resolving the problem.

Code snippet of my modal:

block = {
    "type": "modal",
    "callback_id": "my-callback-id",
    "title": {
        "type": "plain_text",
        "text": "Title",
    },
    "submit": {
        "type": "plain_text",
        "text": "Submit",
    },
    "close": {
        "type": "plain_text",
        "text": "Back",
    },
    "blocks": [
        {
            "type": "input",
            "element": {
                "type": "rich_text_input",
                "action_id": "my-action-id",
                "initial_value": {
                    "type": "rich_text",
                    "elements": [{"type": "user", "user_id": "UXXXXX"}],
                },
            },
            "label": {
                "type": "plain_text",
                "text": "Description",
            },
        }
    ],
}

While this appears to be a broader issue with Slack app modals, I couldn't find a more suitable place to report it. If there's a more appropriate channel for reporting such issues, please guide me accordingly. Your assistance is much appreciated!

The slack_bolt version

slack-bolt==1.18.0
slack-sdk==3.26.1

Python runtime version

Python 3.11.6

OS info

ProductName:            macOS
ProductVersion:         14.1.2
BuildVersion:           23B92
Darwin Kernel Version 23.1.0: Mon Oct  9 21:27:24 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6000

Expected result:

The modal view being submitted, and the backend handler receive the event.

Actual result:

Received an error: "We had some trouble connecting. Try again?". No event triggered.

Hi @lancewl thanks for writing in and providing a great description 💯

I was able to reproduce this behavior with the following app

# app.py
import logging
from slack_sdk import WebClient
from slack_bolt import App, Ack
from slack_bolt.adapter.socket_mode import SocketModeHandler

logging.basicConfig(level=logging.DEBUG)

app = App()

block = {
    "type": "modal",
    "callback_id": "my-callback-id",
    "title": {
        "type": "plain_text",
        "text": "Title",
    },
    "submit": {
        "type": "plain_text",
        "text": "Submit",
    },
    "close": {
        "type": "plain_text",
        "text": "Back",
    },
    "blocks": [
        {
            "type": "input",
            "element": {
                "type": "rich_text_input",
                "action_id": "my-action-id",
                "initial_value": {
                    "type": "rich_text",
                    "elements": [
                        {
                            "type": "rich_text_section",
                            "elements": [
                                {
                                    "type": "user",
                                    "user_id": "UXXXXX",
                                }
                            ],
                        }
                    ],
                },
            },
            "label": {
                "type": "plain_text",
                "text": "Description",
            },
        }
    ],
}


@app.view_submission("my-callback-id")
def view_sub(ack: Ack):
    ack()
    print("view submitted")


@app.command("/hello")
def handle_command(
    ack: Ack, body: dict, client: WebClient
):
    ack()
    client.views_open(trigger_id=body["trigger_id"], view=block)

if __name__ == "__main__":
    # export SLACK_APP_TOKEN=xapp-1-...
    # export SLACK_BOT_TOKEN=xoxb-...
    # python app.py

    SocketModeHandler(app).start()
{
  "display_information": {
    "name": "test-app"
  },
  "features": {
    "slash_commands": [
      {
        "command": "/hello",
        "description": "A test command"
      }
    ],
    "bot_user": {
      "display_name": "test-bot"
    }
  },
  "oauth_config": {
    "scopes": {
      "bot": ["commands", "chat:write", "chat:write.public"]
    }
  },
  "settings": {
    "interactivity": {
      "is_enabled": true
    },
    "org_deploy_enabled": true,
    "socket_mode_enabled": true
  },
  "outgoing_domains": []
}

Results
Submitting the modal with only the default value result in the following 🔴
Screenshot 2023-12-19 at 11 19 12 AM

Editing the default value and then submitting the modal works as expected 🟢

I believe this is a server side issue and does not strictly affect Bolt Python, I will bring this up internally, you can also email our developer support team: support@slack.com about this

👋 It looks like this issue has been open for 30 days with no activity. We'll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.

As this issue has been inactive for more than one month, we will be closing it. Thank you to all the participants! If you would like to raise a related issue, please create a new issue which includes your specific details and references this issue number.