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

Bolt lazy listener with modal submission error #531

Closed
joshight opened this issue Dec 2, 2021 · 5 comments
Closed

Bolt lazy listener with modal submission error #531

joshight opened this issue Dec 2, 2021 · 5 comments
Labels
question Further information is requested

Comments

@joshight
Copy link

joshight commented Dec 2, 2021

(Describe your issue and goal here)

Reproducible in:

pip freeze | grep slack
python --version
sw_vers && uname -v # or `ver`

The slack_bolt version

(Paste the output of pip freeze | grep slack)

Python runtime version

(Paste the output of python --version)
python3.9

OS info

AWS Lambda

(Paste the output of sw_vers && uname -v on macOS/Linux or ver on Windows OS)

Steps to reproduce:

(Share the commands to run, source code, and project settings (e.g., setup.py))

Expected result:

(Tell what you expected to happen)

User enters data into pop-up modal and clicks submit. Submission triggers an API call to create a Jira issue and replies back to user with ticket info.

Actual result:

All of the functionality works as expected - Jira ticket gets created, bot responds to user with details of ticket, but as soon as the user clicks submit on the modal it returns an error "We had some trouble connecting".

(Tell what actually happened with logs, screenshots)

No errors in app logs. Only error is in Slack itself that the user sees as soon as they click submit.

Shouldn't the lazy listener functionality ack the initial response when the user clicks submit and allow time for the additional api call and response in Slack?

Screenshot is attached.

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules
.
Screen Shot 2021-12-02 at 3 19 23 PM

@srajiang
Copy link
Member

srajiang commented Dec 2, 2021

Hey @joshight - how are you ack ing in your view_submission handler?

This previous thread may be helpful to you:
#521

@srajiang srajiang added the question Further information is requested label Dec 2, 2021
@joshight
Copy link
Author

joshight commented Dec 3, 2021

@srajiang Thanks for the link to the other thread. My ack includes a non-empty string, so I don't believe I'm hitting the same issue.

Code is below - please let me know if you see something I'm doing incorrectly. Thanks!

def handle_submission(body, client, view, logger):

    logger.info(body)
    submission_values = view.get("state").get("values")
    request_type = submission_values.get('request_type').get(
        'request-selected').get('selected_option').get('value')
    request_details = submission_values.get('request_details').get(
        'plain_text_input-action').get('value')
    request_url = submission_values.get('request_url').get(
        'static_select-action').get('selected_option').get('value')
    request_region = submission_values.get('request_region').get(
        'static_select-action').get('selected_option').get('value')
    user_id = body["user"]["id"]
    username = body["user"]["name"]
    #response_url = submission_values['response_url']

  
    # Message to send user
    #msg = f'Hi {request_type} {request_details} {request_url} {request_region} {user}'
    user_info = client.users_info(user=user_id)
    first_name = user_info.get('user').get('profile').get('first_name')
    response = f"Thank you for providing ticket details, {first_name}."
    response += f"\nRequest Type - `{request_type}`"
    response += f"\nDetails - `{request_details}`"
    response += f"\nSplunk URL - `{request_url}`"
    response += f"\nAWS Region - `{request_region}`"
    response += "\nA message containing a Jira link will be shared momentarily."

    try:
        client.chat_postMessage(channel=user_id, text=response)
    except BaseException:
        logger.exception("Failed to post a message")

      # Begin Jira input formatting
    description = {
        "request": request_type,
        "splunk_url": request_url,
        "aws_region": request_region,
        "details": request_details,
        "user": username
    }
    desc = json.dumps(description)

    req_body = {
        "channel": user_id,
        "fields": {
            "project": {
                "key": "LOGS"
            },
            "summary": f"Slack Automation - {request_type}",
            "description": desc,
            "issuetype": {
                "name": "Story"
            },
            "customfield_11712": [
                {
                    "name": username
                }
            ],
            "labels": [
                f"{request_type.replace(' ','_')}-automation"
            ]
        }
    }

    jira_message = create_issue(req_body)
    # Message the user
    try:
        client.chat_postMessage(channel=user_id, text=jira_message)
    except BaseException:
        logger.exception("Failed to post a message")


def respond_to_slack(ack):
    ''' Respond to slack within 3 seconds'''
    ack('Long running response incoming!')


APP.view("request-view")(
    ack=respond_to_slack,  # responsible for calling `ack()`
    lazy=[handle_submission]  # unable to call `ack()` / can have multiple functions
)




@srajiang
Copy link
Member

srajiang commented Dec 3, 2021

Oooh @joshight - Thanks for sharing your code sample. You can fix your issue by modifying your code here to return an empty string or nothing,

def respond_to_slack(ack):
''' Respond to slack within 3 seconds'''
ack()

The ack() for view submission handling must actually return either "" (empty string) or {"response_action": ... } data otherwise you get that acknowledgement error in the Slack UI.

@seratch
Copy link
Member

seratch commented Dec 3, 2021

@joshight
FWIW, let me add an example of response_action usage.

If you want to display some loading message on the modal after submission, you can do something similar to the following example (the app code is built with bolt-js but you can do the same with bolt-python):

@joshight
Copy link
Author

joshight commented Dec 3, 2021

@seratch @srajiang Thank you so much! That resolved my issue. You have done an awesome job with the bolt framework. It's very easy to work with and prior to the lazy listener I had to decouple long running tasks with sqs to call another lambda function that ran in parallel.

@joshight joshight closed this as completed Dec 3, 2021
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

3 participants