Is there a way to combine 2 decorators in python with or condition?

Viewed 68

I am using RTMclient to get slack message data. Here the type of message is 'message' which only gives us the data of parent thread. But I want the message data of replies. On research I found it is 'message_replied' type. I want to include either message or message_replied in decorator.

Pfb a sample code.

@slack.RTMClient.run_on(event='message')
def respond(**payload):
    data = payload['data']
    web_client = payload['web_client']
    rtm_client = payload['rtm_client']
    user_id = data.get("user")

text = data.get("text")

Here I want to use @slack.RTMClient.run_on(event='message_replied') also but with 'or' condition

1 Answers

Looking at the source code for slack.RTMClient.run_on(), you should be able to "stack" the decorators like so:

@slack.RTMClient.run_on(event='message')
@slack.RTMClient.run_on(event='message_replied')
def respond(**payload):
    data = payload['data']
    web_client = payload['web_client']
    rtm_client = payload['rtm_client']
    user_id = data.get("user")

Have you tried this?

Related