Repository navigation
How to use lazy listener for basic message event listening and responding ? #440
Description
Activity
Hello @kunalrc777,
Have you tried following the lazy listener documentation in Bolt Python? There is even an entire sample lazy listener on Lambda application that this documentation links to and can be a useful guide.
It is difficult for me to help you without more information. What error do you receive, if any? What do the access logs for your application show? How is your application organized? How is it exposed publicly?
- addedquestionFurther information is requestedFurther information is requested
on Aug 11, 2021 I have gone through above folders and the doc page but i couldn't find a similar to my requirement.
I am trying to use chat.postMessage to send the the message to slack in response the the incoming event message.As messages are not getting sent due to 3 seconds callback, i have been suggested to use lazy_listener feature from slack.
Could you please tell me how can i use this feature to send chat.postmessage with message event.I am taking a look at updating the example to make it clearer - your patience is appreciated while I work through the example.
Hello @kunalrc777 ,
I have added a README and some fixes to the lazy AWS examples app: https://github.com/slackapi/bolt-python/tree/main/examples/aws_lambda
I hope it can help you get set up properly. I was followed the instructions I wrote up and was able to get a Bolt Python app up on AWS Lambda within minutes.
If it solves your problem, can you please close this issue? Thank you
Hey @filmaj , Thanks for quick response and updated setup process.
As this setup contains slash command, Could you please help me with how can i implement the same setup for simple message method and respond using client.chat_postMessage ?In these cases -- >
https://slack.dev/bolt-python/concepts#event-listening
or
https://slack.dev/bolt-python/concepts#message-sending@kunalrc777 you can use the exact same approach as in the AWS Lazy Lambda listener approach, but instead of configuring your app with a Slash Command under api.slack.com/apps, you would set up your app with Event Subscriptions. You would need to have your app listen to an event for a message, such as
messages.readbot event, and in the Request URL you would use your deployed API Gateway / AWS Lambda combination URL as per the example instructions.Hi @kunalrc777, as Fil mentioned, you can use the same approach for
app.event/app.messagelisteners. The only difference is that, to use lazy listeners, you useapp.messageas a method, not a decorator. See the following example to know how it looks like:# Note that, with process_before_response=True, # the `ack` function needs to complete within 3 seconds app = App(process_before_response=True) def do_something_within_3_seconds(): # If you don't have anything to do wihtin 3 seconds, # this function does not need to do anything pass def send_message_later(message, say): # Do something that may take longer than 3 seconds here results = call_backend_services() say(f"Hi there, <@{message['user']}>!") app.message(":wave:")( ack=do_something_within_3_seconds, lazy=[send_message_later] )
See the updated lazy listener app example as well: https://github.com/slackapi/bolt-python/blob/main/examples/aws_lambda/lazy_aws_lambda.py
I belive that we've provided an answer to your question here. If everything is clear now, would you mind closing this issue?
- Hey, Thanks for the detailed information. Appreciate it. For sure, you can lose this ticket. Thanks and Regards, Kunal Chauudhari…On Fri, Aug 13, 2021 at 11:05 PM Kazuhiro Sera ***@***.***> wrote: Hi @kunalrc777 <https://github.com/kunalrc777>, as Fil mentioned, you can use the same approach for app.event / app.message listeners. The only difference is that, to use lazy listeners, you use app.message as a method, not a decorator. See the following example to know how it looks like: # Note that, with process_before_response=True,# the `ack` function needs to complete within 3 secondsapp = App(process_before_response=True) def do_something_within_3_seconds(): # If you don't have anything to do wihtin 3 seconds, # this function does not need to do anything pass def send_message_later(message, say): # Do something that may take longer than 3 seconds here results = call_backend_services() say(f"Hi there, <@{message['user']}>!") app.message(":wave:")( ack=do_something_within_3_seconds, lazy=[send_message_later] ) See the updated lazy listener app example as well: https://github.com/slackapi/bolt-python/blob/main/examples/aws_lambda/lazy_aws_lambda.py I belive that we've provided an answer to your question here. If everything is clear now, would you mind closing this issue? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#440 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/APCWIHP2XDDB7IYXRIFSH6TT4XMRBANCNFSM5B63OMRQ> . Triage notifications on the go with GitHub Mobile for iOS <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android <https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email> .
I am using serverless lambda to deploy the python slack-bolt code. Whenever i am using events api, it's not responding in the slack.
Please help me to know that how can i use the this basic code with lazy listener