-
Notifications
You must be signed in to change notification settings - Fork 251
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
Need help to run lazy listeners in response to view_submission requests on AWS Lambda #521
Comments
An example from docs is not working too: def testing_whatever(respond, body):
time.sleep(5) # longer than 3 seconds
respond(f"Completed! (test task: {body or 'empty'})")
app.command("/test")(
ack=respond_to_slack_within_3_seconds,
lazy=[testing_whatever]
) |
Hi @ashalobodin - Thanks for writing in, and for providing your sample code. Your code does appear to correctly follow the documentation (and odd that you report it previously was working, then stopped worked), so I will see whether I can replicate this behavior and get back to you. |
HI @ashalobodin - Unfortunately I'm not able to recreate the behavior you're experiencing. With the following code deployed to AWS Lambda, I am able to successfully call import logging
import time
from slack_bolt import App
from slack_bolt.adapter.aws_lambda import SlackRequestHandler
# process_before_response must be True when running on FaaS
app = App(process_before_response=True)
@app.middleware # or app.use(log_request)
def log_request(logger, body, next):
logger.debug(body)
return next()
command = "/hello-bolt-python-lambda"
view = "create_doc"
def respond_to_slack_within_3_seconds(body, ack):
if body.get("text") is None:
ack(f":x: Usage: {command} (description here)")
else:
title = body["text"]
ack(f"Accepted! (task: {title})")
def process_request_with_view(respond, body):
time.sleep(5)
title = body["text"]
respond(f"Completed! (task: {title})")
def handle_freeform_submission(body, client, view):
slack_user_id = body['user']['id']
time.sleep(5)
client.chat_postMessage(channel=slack_user_id, text='some msg')
@app.command(command)
def publish_view(client, body, ack, respond):
ack()
client.views_open(trigger_id=body['trigger_id'], view={
"type": "modal",
# View identifier
"callback_id": view,
"title": {"type": "plain_text", "text": "Updated modal"},
"submit": {"type": "plain_text", "text": "Submit"},
"blocks": [
{
"type": "section",
"text": {"type": "plain_text", "text": "You updated the modal!"}
},
{
"type": "image",
"image_url": "https://media.giphy.com/media/SVZGEcYt7brkFUyU90/giphy.gif",
"alt_text": "Yay! The modal was updated"
}
]
})
app.view(view)(ack=respond_to_slack_within_3_seconds, lazy=[handle_freeform_submission])
SlackRequestHandler.clear_all_log_handlers()
logging.basicConfig(format="%(asctime)s %(message)s", level=logging.DEBUG)
def handler(event, context):
slack_handler = SlackRequestHandler(app=app)
return slack_handler.handle(event, context) This example also includes some additional logging steps which may be illustrative in figuring out what's happening. Are you able to provide the full logs for the failures you're seeing? |
FWIW, I noticed the example code in this repo was a bit broken ( If your error is caused by this, sorry about the confusing example. >>> time.sleep(3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'time' is not defined
>>>
>>> import time
>>> time.sleep(3)
>>> |
Hey there, Thank you very much for your responses. I just copied the code @srajiang provided and failed again - Submitting modal results in The only difference is how we get (from AWS SecretsManager) and use secrets:
A piece of logging from lambda Might it be related to improper using of secrets? |
@ashalobodin Perhaps, some other parts of your AWS components may handle the requests instead. Can you make sure if the Request URL in the Interactivity & Shortcuts section is a valid URL? It may not the one of the deployed Lambda (+ API Gateway). |
@seratch @ashalobodin Ask: @ashalobodin Can take a look below and let me know whether you can also recreate the following behavior using my updated code sample? I want to figure out if your issue is the same or different. I've revised my code to make the logic which handles the view publishing also lazy for clarity (and included that below) Steps:
From looking at these, my guess is there might be a bug related to Revised Code Sample import logging
import time
from slack_bolt import App
from slack_bolt.adapter.aws_lambda import SlackRequestHandler
# process_before_response must be True when running on FaaS
app = App(process_before_response=True)
@app.middleware # or app.use(log_request)
def log_request(logger, body, next):
logger.debug(body)
return next()
command = "/hello-bolt-python-lambda"
view = "create_doc"
def respond_to_slack_within_3_seconds(body, ack):
if body.get("text") is None:
ack(f":x: Usage: {command} (description here)")
else:
title = body["text"]
ack(f"Accepted! (task: {title})")
def handle_freeform_submission(body, client, view):
slack_user_id = body['user']['id']
time.sleep(5)
client.chat_postMessage(channel=slack_user_id, text='some msg')
def publish_view(client, body, ack, respond):
ack()
client.views_open(trigger_id=body['trigger_id'], view={
"type": "modal",
# View identifier
"callback_id": view,
"title": {"type": "plain_text", "text": "Updated modal"},
"submit": {"type": "plain_text", "text": "Submit"},
"blocks": [
{
"type": "section",
"text": {"type": "plain_text", "text": "You updated the modal!"}
},
{
"type": "image",
"image_url": "https://media.giphy.com/media/SVZGEcYt7brkFUyU90/giphy.gif",
"alt_text": "Yay! The modal was updated"
}
]
})
app.command(command)(ack=respond_to_slack_within_3_seconds, lazy=[publish_view])
app.view(view)(ack=respond_to_slack_within_3_seconds, lazy=[handle_freeform_submission])
SlackRequestHandler.clear_all_log_handlers()
logging.basicConfig(format="%(asctime)s %(message)s", level=logging.DEBUG)
def handler(event, context):
slack_handler = SlackRequestHandler(app=app)
return slack_handler.handle(event, context)
# export SLACK_SIGNING_SECRET=***
# export SLACK_BOT_TOKEN=xoxb-***
# rm -rf vendor && cp -pr ../../src/* vendor/
# pip install python-lambda
# lambda deploy --config-file aws_lambda_config.yaml --requirements requirements.txt |
Hey @srajiang, |
Thank you both! It seems that we don't need to worry about 202 HTTP status here (sorry about confusing you!).
This is your code's issue. The # the existing `respond_to_slack_within_3_seconds` is compatible with slash commands
# but it's not with view submission
def ack_view_submission_within_3_seconds(ack):
ack()
app.view(view)(
ack=ack_view_submission_within_3_seconds,
lazy=[handle_freeform_submission]
) @ashalobodin FWIW, I am guessing that one possible cause of your issue would be unmatching
This is because the above code does so. If you modify the def respond_to_slack_within_3_seconds(ack):
ack() It seems that everything is clear now. Let us know if you have follow-ups. I hope you'll figure out the issue in your code and make your app functioning as you expect! |
Yes, I see. Thank you for catching that - I think there could be some improvements to our docs on |
I can't receive a response from a lazy function (in AWS lambda).
Although, the same AWS lambda was working a few days ago.
Reproducible in:
The
slack_bolt
versionslack-bolt 1.9.2 # and any above
slack-sdk 3.11.2
Python runtime version
python3.7
Steps to reproduce:
are the same as in Issue #490
Expected result:
The function
handle_freeform_submission
should be called and send its result to a user.Actual result:
Modal (code base not presented) opens and could be submitted with data
But the lazy function doesn't seem to be even called.
Here is a piece of lambda logs:
![Screenshot 2021-11-11 at 21 03 27](https://user-images.githubusercontent.com/32097675/141354386-b1d6c372-1160-4aa9-aa74-0d71a5cb58ec.png)
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: