bolt-python icon indicating copy to clipboard operation
bolt-python copied to clipboard

Error in : dialogs_app.py

Open jambeshmpt opened this issue 4 years ago • 9 comments

When i run this bolt python app and try to submit - the UI Screen just stuck without closing and it shows error - "We had some trouble connecting . Try Again"

i did a print and the UI accept and print the value in terminal but the dialog never close/submit.

jambeshmpt avatar Sep 13 '22 01:09 jambeshmpt

Hi @jambeshmpt! The response you're getting seems to indicate that the view submission isn't being handled by your application.

Is the application one that we have published as an example, or is this one that you created?

In either case, can you confirm that you have a view submission listener that uses the same view callback ID of the modal you're submitting?

misscoded avatar Sep 13 '22 03:09 misscoded

@jambeshmpt If I understand correctly, you are trying to run https://github.com/slackapi/bolt-python/blob/v1.14.3/examples/dialogs_app.py, right? I just confirmed the example app is still valid. It worked for me without any issues. Please go to https://api.slack.com/apps/{your app ID}/interactive-messages and make sure whether the Interactivity feature is enabled and a valid Request URL is set as necessary.

Also, as @misscoded mentioned, using modal views is the currently recommended way. You can find an equivalent example using a modal view here.

I hope this was helpful to you.

seratch avatar Sep 13 '22 03:09 seratch

@jambeshmpt If I understand correctly, you are trying to run https://github.com/slackapi/bolt-python/blob/v1.14.3/examples/dialogs_app.py, right? I just confirmed the example app is still valid. It worked for me without any issues. Please go to https://api.slack.com/apps/{your app ID}/interactive-messages and make sure whether the Interactivity feature is enabled and a valid Request URL is set as necessary.

Also, as @misscoded mentioned, using modal views is the currently recommended way. You can find an equivalent example using a modal view here.

I hope this was helpful to you.

I am using socket mode from Interactivity & shortcuts and for socket mode the URL is not require as per the options socket-mode

i using the exact code from the github using socketmode

jambeshmpt avatar Sep 13 '22 04:09 jambeshmpt

Hi @jambeshmpt! The response you're getting seems to indicate that the view submission isn't being handled by your application.

Is the application one that we have published as an example, or is this one that you created?

In either case, can you confirm that you have a view submission listener that uses the same view callback ID of the modal you're submitting?

Thank you @misscoded , Yes i am using the same code from github without any change and running under socket mode .

one positive point is - when i submit it actually going to the below code
@app.action("dialog-callback-id") def dialog_submission_or_cancellation(ack: Ack, body: dict): submission = body["submission"] print(submission["server_name"])

this does print one of the text I entered in the text input field but the modal dialog stay as-is and shows error when i submit . error

jambeshmpt avatar Sep 13 '22 04:09 jambeshmpt

@jambeshmpt Thanks for your reply. Could you share your whole source code to reproduce the issue? I've already confirmed the dialog example code works even with SocketModeHandler. I may be able to detect some difference in your code.

seratch avatar Sep 13 '22 04:09 seratch

@jambeshmpt Thanks for your reply. Could you share your whole source code to reproduce the issue? I've already confirmed the dialog example code works even with SocketModeHandler. I may be able to detect some difference in your code.

Here is the code i am running -

import logging
import os
import re

from dotenv import load_dotenv

from slack_bolt import App, Ack
from slack_bolt.adapter.socket_mode import SocketModeHandler

#load_dotenv()

#SLACK_APP_TOKEN = os.environ["SLACK_APP_TOKEN"]
#SLACK_BOT_TOKEN = os.environ["SLACK_BOT_TOKEN"]

SLACK_APP_TOKEN = "_xapp-1-A03UW7H2V35-3967802867255-"_
SLACK_BOT_TOKEN = "_xoxb-378962989360-3982598991731-_"

app = App(token=SLACK_BOT_TOKEN, name="tabslash")
logger = logging.getLogger(__name__)


#########

@app.command("/tabforslack")
def test_command(body, client, ack, logger):
    logger.info(body)
    ack("I got it!")
    res = client.dialog_open(
        trigger_id=body["trigger_id"],
        dialog={
            "callback_id": "dialog-callback-id",
            "title": "Request for New Project",
            "submit_label": "Request",
            "notify_on_cancel": True,
            "state": "Limo",
            "elements": [
                {"type": "text",
                 "label": "Server Name",
                  "name": "server_name"
                  },
                {
                    "type": "text",
                    "label": "Site Name",
                    "name": "site_name",
                },
                {
                    "label": "Project Name",
                    "name": "project_name",
                    "type": "text",
                },

               {   
                    "label": "Project Owner ID",
                    "name": "owner_id",
                    "type": "text",
                },




            ],
        },
    )
    logger.debug(res)


  ##ack section ##

@app.action("dialog-callback-id")
def dialog_submission_or_cancellation(ack: Ack, body: dict):
    if body["type"] == "dialog_cancellation":
        # This can be sent only when notify_on_cancel is True
        ack()
        return

    errors = []
    submission = body["submission"]
    print(submission["server_name"])
   
    if submission["server_name"] != "production":
        errors = [
            {
                "name": "server_name",
                "error": "server , site , project ,owner must be valid ",
            }
        ]
    if len(errors) > 0:
        # or ack({"errors": errors})
        ack(errors=errors)
    else:
       ack(f"Your Project Request Submitted {submission}")



def main():
    handler = SocketModeHandler(app, SLACK_APP_TOKEN)
    handler.start()


if __name__ == "__main__":
    main()

jambeshmpt avatar Sep 13 '22 06:09 jambeshmpt

@jambeshmpt

ack(f"Your Project Request Submitted {submission}")

This ack() method should not have any str argument. Like the original example does, ack() should work for you.

seratch avatar Sep 13 '22 06:09 seratch

@jambeshmpt

ack(f"Your Project Request Submitted {submission}")

This ack() method should not have any str argument. Like the original example does, ack() should work for you.

Thanks !! That worked .

jambeshmpt avatar Sep 13 '22 06:09 jambeshmpt

Glad to hear that!

seratch avatar Sep 13 '22 06:09 seratch