Skip to content

Enable to use instance/class methods for listeners #174

Description

@seratch

Currently, App/AsyncApp accepts only static methods as listeners. Developers may want to use instance/class methods in a class for some reason. We can update the kwrags_injection mechanism to accept cls, self along with other args.

from slack_bolt import App
app = App()

class Foo:
    def i(self, ack):
        ack()

    @classmethod
    def c(cls, ack):
        ack()

    @classmethod
    def c2(cls):
        def _c(ack):
            ack()
        return _c

    @staticmethod
    def s(ack):
        ack()


foo = Foo()

# This works
@app.command('/hello-bolt-python')
def handle(ack):
    ack()

# This works
app.command('/hello-bolt-python')(handle)

# This does not work
app.command('/hello-bolt-python')(foo.i)

# This does not work
app.command('/hello-bolt-python')(Foo.c)

# This works
app.command('/hello-bolt-python')(Foo.c2())

# This works
app.command('/hello-bolt-python')(Foo.s)

Category (place an x in each of the [ ])

  • slack_bolt.App and/or its core components
  • slack_bolt.async_app.AsyncApp and/or its core components
  • Adapters in slack_bolt.adapter
  • Others

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions