Skip to content

How to use lazy listener for basic message event listening and responding ? #440

Description

@kunalrc777

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

# This will match any message that contains 👋
@app.message(":wave:")
def say_hello(message, say):
    user = message['user']
    say(f"Hi there, <@{user}>!") 

Activity

  1. filmaj commented on Aug 11, 2021

    @filmaj
    Contributor

    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?

  2. self-assigned this
    on Aug 11, 2021
  3. kunalrc777 commented on Aug 11, 2021

    @kunalrc777
    Author

    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.

  4. filmaj commented on Aug 11, 2021

    @filmaj
    Contributor

    I am taking a look at updating the example to make it clearer - your patience is appreciated while I work through the example.

  5. filmaj commented on Aug 11, 2021

    @filmaj
    Contributor

    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

  6. kunalrc777 commented on Aug 11, 2021

    @kunalrc777
    Author

    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

  7. filmaj commented on Aug 11, 2021

    @filmaj
    Contributor

    @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.read bot event, and in the Request URL you would use your deployed API Gateway / AWS Lambda combination URL as per the example instructions.

  8. seratch commented on Aug 14, 2021

    @seratch
    Contributor

    Hi @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 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?

  9. kunalrc777 commented on Aug 14, 2021

    @kunalrc777
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions