-
Notifications
You must be signed in to change notification settings - Fork 248
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
Ack() on successfull view submission throwing connection error #1215
Comments
Hi, @pmanuel-rossi! Thank you for submitting this issue. To clarify, after you submit the modal, what is your expected behavior? For the modal view to update or for the modal to close? |
The "tags_submitted_view" is the view that is updated into the modal after processing, and is working correctly, but the message still appears. |
@pmanuel-rossi thanks for the clarification! It looks like you're currently pushing the new view for the modal using the view submitted listener, is that right? If it's through the view submitted listener, you might need to update your modal view via a |
Hello, thank you for your response, I just tried that again following this documentation for python bolt and the whole process runs but the view does not update, it just throws the aforementioned connection error, my ack call with the response action as posed in the docs: |
Hello, so today I tried to fix this again and I'm really thinking that it's a bug on the ack method, or I'm not being able to find docs that explain how to prevent this (I've tried the lazy listener method since I'm running this in a serverless architecture, the response_action method and some mixtures between both). |
@pmanuel-rossi If you're trying to use ack w/ response_action within your lazy listener, unfortunately it does not work. ack() method must be called on the synchronous method (meaning the "ack" function parameter) and it must completew within 3 seconds. Other operations like calling any Slack APIs can be asynchronously done on the lazy listener side. Hope this helps you figure things out. If you need further assitance, please share working example code demonstrating your app's behavior. With that, we may be able to provide more specific guidance. |
Hello, thank you for your prompt response. I tried to do it via the lazy listener as follows: def register_user_tags(body, client, view):
#Does some stuff
try:
#Runs a function to register the submitted tags
print('[INFO] Tags registered!')
client.views_update(view_id=view["id"], view=_tags_submitted_view)
except Exception as e:
print(f'[ERROR] Could not update user {user_alias}: {e}')
return None This works perfectly (the view updates and the process to process the user input works) in under one second, but the message still appears. As far as I can tell, since I am using a Lambda function to do this this is the right method but I have also tried only using the ack w/ response method without the lazy listener and the result is the same. The _tags_submitted_view is the following : And the responw within 3 seconds function only acknwledges the request: def respond_to_slack_within_3_seconds(body: Dict, ack: Callable):
print("[INFO] Using 3 second acknowledgement")
ack() Thank you for giving this a look! |
If the respond_to_slack_within_3_seconds function works as expected, the modal should close immediately. If it doesn't, this indicates that your HTTP response from the ack() method isn't being delivered for some reason. I suggest checking how your app responds to a Slack view_submission request by investigating your API Gateway / Cloudwatch logs. It might not be responding with a 200 OK status. Another possibility is that you haven't configured the Request URL in the Interactivity & Shortcuts section. If your app opens a modal from a slash command invocation but only has the slash command's Request URL configured, this missing configuration could be the cause. |
Ah, never mind about the Request URL configuration suggestion. Your lazy listeners are running, so the view_submission event request should be delievered to your lambda endpoint for sure. |
Ok, so just to see if I got this right, when the submit button is clicked, the register_user_tags function is triggered, which updates the view, and the modal should close immediately if it was working correctly? How could I update the view to tell the user that the process was successfully executed? I will check on the response for the view submission on my api logs. |
No, I mean calling ack() without arguments for a view_submission request closes the current modal. If you pass response_action etc. to the ack() method, this behavior can be customizable. So, for your use case, the best solution is to call ack() with repsonse_action="update" in "respond_to_slack_within_3_seconds" function, plus doing time consuming stuff and then calling views.update API with the result view in lazy "register_user_tags" function, like you're trying to do. What happens if you simplify the code to have only respond_to_slack_within_3_seconds function? Also, could you check the AWS logs to check what's actually happening? |
My ChatGPT example app runs on AWS Lambda and the app does what you want to do. Checking the code and its behavior may help: |
That example that you sent me is genius! Thank you I see what I was doing wrong now, I will try that and get back to you with huge thanks hopefully 💯 |
So, I tried your suggestion and simplified my code, the response for the response_action update is as follows accorting to cloudtrail: {
"httpMethod": "POST",
"idAccountId": "-",
"idCaller": "-",
"idSourceIp": "3.91.35.34",
"idUserAgent": "Slackbot 1.0 (+https://api.slack.com/robots)",
"idUserArn": "-",
"intError": "-",
"intLatency": "145",
"intStatus": "200",
"path": "/slackbot",
"protocol": "HTTP/1.1",
"requestId": "CWKIFhMPPHcESpg=",
"requestTime": "06/Dec/2024:01:44:32 +0000",
"requestTimeEpoch": "1733449472",
"responseLength": "95",
"status": "200"
} I also checked with printing the response of the ack with the following code: res = ack(response_action="update", view=_tags_submitted_view)
print("Ack response: ", res.status) it also returns a 200 As for the response for the views_update, it is as follows:
and the view updates correctly, so I'm pretty lost again :/ |
Your old code might have some errors or unintentional modification. So, is your app now working as you expect? |
Yup, everything is working fine. |
Great to hear that! I'll close this thread for now, but whenever you have a different question, please feel free to submit a new one! |
No, the app is working as expected but the "trouble connecting" message is still being shown. So the same problem than I started with. |
Okay, I've reopened this issue, but I don't have any further suggestions with the given information. |
Sorry about the confusion, thank you for reopening this. So the code currently is as follows: def just_ack(ack: Ack):
ack() This executes when a button is pushed in the home tab def sc_view(body, logger, client):
try:
# Service tags
#Executes a process that takes a couple ms.
view = {
"type": "modal",
"callback_id": "tag-registry",
"title": {
"type": "plain_text",
"text": "Tag subscription."
},
"submit": { "type": "plain_text", "text": "Submit" },
"blocks": [
{
"type": "rich_text",
"elements": [
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": "This will help you select the most appropriate tags so that you recieve the information that you need, please select all that apply from the following sections, if the section does not apply, please leave it blank."
}
]
}
]
},
{
"type": "input",
"element": {
"type": "multi_static_select",
"placeholder": {
"type": "plain_text",
"text": "Select options",
"emoji": True
},
"options": create_view_options(tags),
"action_id": "select_programs"
},
"label": {
"type": "plain_text",
"text": "Label",
"emoji": True
},
"block_id": "supply_chain_input_block"
}
]
}
client.views_open(trigger_id=body["trigger_id"], view=view)
def ack_supply_chain_tag_registry(body, view, ack):
input_blocks = view["state"]["values"]
tag_selection = [i["value"] for i in input_blocks["supply_chain_input_block"]["select_programs"]["selected_options"]]
try:
#This controller takes less than 5ms to execute
user_controller: User = UserController().register_tags(user_alias, supply_chain_program_tag_selection)
print('[INFO] Tags registered!')
ack(response_action="update", view=_tags_submitted_view)
except Exception as e:
print(f'[ERROR] Could not update user {user_alias}: {e}')
return None
_tags_submitted_view = {
"type": "modal",
"title": {
"type": "plain_text",
"text": "My App",
"emoji": True
},
"close": {
"type": "plain_text",
"text": "Cancel",
"emoji": True
},
"blocks": [
{
"type": "section",
"text": {
"type": "plain_text",
"text": "This is a plain text section block.",
"emoji": True
}
}
]
}
def display_successfull_tag_registry(client, payload):
client.views_update(view_id=payload["id"], view=_tags_submitted_view)
def register_listeners(app: App):
# The sc-option is the id of the button, it works perfectly
app.action("sc-option")(ack=just_ack, lazy=[sc_view])
app.view("tag-registry")(ack=ack_supply_chain_tag_registry, lazy =[display_successfull_tag_registry]) On the lambda function execution, I call the register_listeners function outside the lambda handler, which is the following: def process_notifications(event, context):
print("Received request")
SlackRequestHandler.clear_all_log_handlers()
slack_handler = SlackRequestHandler(app=app)
# The app is self recursive!
if "Records" in event:
event = json.loads(event.get("Records", [])[0].get("Sns", {}).get("Message", ""))
print("Received SNS event:", event)
return slack_handler.handle(event, context) As far as I can tell everything is correct and it actually works wonders in under 0.5s, but the last view shows the following: As I mentionned, the responses are the following: ack() response: {
"httpMethod": "POST",
"idAccountId": "-",
"idCaller": "-",
"idSourceIp": "3.91.35.34",
"idUserAgent": "Slackbot 1.0 (+https://api.slack.com/robots)",
"idUserArn": "-",
"intError": "-",
"intLatency": "145",
"intStatus": "200",
"path": "/slackbot",
"protocol": "HTTP/1.1",
"requestId": "CWKIFhMPPHcESpg=",
"requestTime": "06/Dec/2024:01:44:32 +0000",
"requestTimeEpoch": "1733449472",
"responseLength": "95",
"status": "200"
} views_update response: {'ok': True, 'view': {'id': '---', 'team_id': '---', 'type': 'modal', 'blocks': [{'type': 'section', 'block_id': '---', 'text': {'type': 'plain_text', 'text': 'This is a plain text section block.', 'emoji': True}}], 'private_metadata': '', 'callback_id': '', 'state': {'values': {}}, 'hash': '---', 'title': {'type': 'plain_text', 'text': 'My App', 'emoji': True}, 'clear_on_close': False, 'notify_on_close': False, 'close': {'type': 'plain_text', 'text': 'Cancel', 'emoji': True}, 'submit': None, 'previous_view_id': None, 'root_view_id': '---', 'app_id': '---', 'external_id': '', 'app_installed_team_id': '---', 'bot_id': '---'}} Thank you for any help that you might provide, I have been looking everywhere for why that message still appears and nothing. |
Thanks for sharing more details. I’d suggest checking if the same situation arises without our AWS Lambda settings. You can quickly run the same app on your local machine by switching from the AWS Lambda adapter to the built-in web server/Socket Mode adapter. Also, running the example app I shared above and checking for differences might be helpful too. |
👋 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. |
(Filling out the following details about bugs will help us solve your issue sooner.)
Reproducible in:
The
slack_bolt
version1.17.0
Python runtime version
3.9
OS info
Using lambda with X86_64 Architecture
Steps to reproduce:
(Share the commands to run, source code, and project settings (e.g., setup.py))
3.return an Ack with an error
Expected result:
Model view update has no connection error message since it worked properly
Actual result:
All functionality for the function works correctly, and the model even refreshes in less than one second but it throws the following error:
View submission:
tags_submitted_view = { "type": "modal", "title": { "type": "plain_text", "text": "My App", "emoji": True }, "close": { "type": "plain_text", "text": "Cancel", "emoji": True }, "blocks": [ { "type": "section", "text": { "type": "plain_text", "text": "This is a plain text section block.", "emoji": True } } ] }
I am using the lazy listener method to avoid timeout errors but still not working:
app.view("tag-registry")(ack=respond_to_slack_within_3_seconds, lazy =[register_user_tags])
The respond to slack within 3 seconds function is just acknowledging, the process takes less than a second:
def respond_to_slack_within_3_seconds(body: Dict, ack: Callable):
print("[INFO] Using 3 second acknowledgement")
ack()
Everything is working as expected and no errors are thrown in the log but the error still appears.
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.
The text was updated successfully, but these errors were encountered: