Skip to content

Assistant listener middleware crashes when given a plain function #1597

Description

@sahiljagtap08

Reproducible in:

The slack_bolt version

slack_bolt==1.30.0
slack_sdk==3.45.0

Python runtime version

Python 3.12.5

OS info

macOS 27.0

Steps to reproduce:

Pass a plain function as listener middleware on an Assistant listener.

from slack_bolt import App, Assistant

app = App(token="xoxb-...", signing_secret="secret")
assistant = Assistant()

def my_middleware(next):
    next()

@assistant.user_message(middleware=[my_middleware])
def handle(say):
    say("hi")

app.use(assistant)
  1. Register the listener above.
  2. Send a user message in an assistant thread.

Expected result:

The function is accepted as middleware, the same way @app.event(..., middleware=[my_middleware]) accepts it.

Actual result:

Every matching event fails with AttributeError: 'function' object has no attribute 'process'.

Assistant.build_listener in slack_bolt/middleware/assistant/assistant.py (and AsyncAssistant in async_assistant.py) treats every item in middleware as a Middleware instance. App wraps plain functions in CustomMiddleware, but the assistant does not. It also calls middleware.insert(0, ...) on the list the caller passed in, so the caller's list is changed.

I have a fix with sync and async tests in #1591.

Requirements

I have read the Contributing guidelines and Code of Conduct.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions