def __call__(*args, **kwargs): functions = self._to_listener_functions(kwargs) if kwargs else list(args) primary_matcher = builtin_matchers.event( {"type": "message", "subtype": None} ) middleware.append(MessageListenerMatches(keyword)) return self._register_listener( list(functions), primary_matcher, matchers, middleware, True )
def __call__(*args, **kwargs): functions = self._to_listener_functions( kwargs) if kwargs else list(args) # As of Jan 2021, most bot messages no longer have the subtype bot_message. # By contrast, messages posted using class app's bot token still have the subtype. constraints = {"type": "message", "subtype": (None, "bot_message")} primary_matcher = builtin_matchers.event(constraints=constraints) middleware.append(MessageListenerMatches(keyword)) return self._register_listener(list(functions), primary_matcher, matchers, middleware, True)
def __call__(func): primary_matcher = builtin_matchers.event("message") def keyword_matcher(payload) -> bool: text: Optional[str] = payload.get("event", {}).get("text", {}) if text: if isinstance(keyword, Pattern): return keyword.match(text) # type: ignore elif isinstance(keyword, str): return keyword in text return False matchers.insert(0, keyword_matcher) return self._register_listener(func, primary_matcher, matchers, middleware, True)
def test_events(self): request = BoltRequest(body=json.dumps(event_payload)) m = event("app_mention") assert m.matches(request, None) m = event({"type": "app_mention"}) assert m.matches(request, None) m = event("message") assert not m.matches(request, None) m = event({"type": "message"}) assert not m.matches(request, None) request = BoltRequest( body=f"payload={quote(json.dumps(shortcut_payload))}") m = event("app_mention") assert not m.matches(request, None) m = event({"type": "app_mention"}) assert not m.matches(request, None)
def __call__(*args, **kwargs): functions = self._to_listener_functions( kwargs) if kwargs else list(args) primary_matcher = builtin_matchers.event(event, True) return self._register_listener(list(functions), primary_matcher, matchers, middleware, True)
def __call__(func): primary_matcher = builtin_matchers.event(event, True) return self._register_listener(func, primary_matcher, matchers, middleware, True)