PubSub moderator actions for multiple channels

I realize that this is not part of the official PubSub documentation, but it’s possible to listen to multiple channels’ chat_moderator_actions. towards this end, my software uses this syntax i stole from the live website

ws.send(json.dumps({"type": "LISTEN", "nonce": nonce, "data": {"auth_token": auth_token, "topics": ["chat_moderator_actions.{}.{}".format(my_id, channel_id) for channel_id in channel_ids]}}))

this creates a single listen request with TWO topics; each with a separate channel_id for the two channels i’d like to receive moderator actions for. this works, since the auth_token grants me permission to listen to each channel’s moderator actions since i’m a moderator in both.

however, there’s an issue with the responses when i execute a moderator command in either of the two channels (or both): the event that is broadcast from, e.g., a ban, can’t be pinned down to one specific channel. in the following example, i’ve banned the user “test” in both channels. upper caps values are anonymized.

{'data': {'type': 'chat_login_moderation', 'moderation_action': 'ban', 'args': ['test', ''], 'created_by': 'MYUSER', 'created_by_user_id': 'MYID', 'msg_id': '', 'target_user_id': '12427', 'target_user_login': '', 'from_automod': False}}
{'data': {'type': 'chat_login_moderation', 'moderation_action': 'ban', 'args': ['test', ''], 'created_by': 'MYUSER', 'created_by_user_id': 'MYID', 'msg_id': '', 'target_user_id': '12427', 'target_user_login': '', 'from_automod': False}}

as you can see, the events appear identical although they are each tied to specific channels. the same issue arises when i get a moderation event from just one channel - i can’t pin down which of the two i’ve got listen requests on it stems.

the obvious workaround to this seems to be to just create a separate connection for each channel with their separate auth_tokens, by-the-book topics and to store in my own code the respective channel names, but that seems very wasteful towards the 10 connections/ip limit.

is this an oversight in the data definition, or am i misunderstanding the intent behind the design of allowing up to 50 topics for one connection?

As per


chat_moderator_actions.<channel ID>

is supported. So there’s your problem, you are trying to read an undocumented topic, and the undocumented topic doesn’t do what you need it to do.

But each message sent over pubsub, should take the format:

    topic: thetopic
    message: AnotherJson

So you should be able to parse the topic key for the channelID

I use one connection with multiple pairs of topics and auth keys. So you can listen to 10 channels with 10 different auth keys, just send multiple listens. And parse the topic key of each message to see which topic it’s for.

I read the topic. Split around ‘.’ and use the first party to route to the right handler and the second for which channel the message is for

good grief, i’m an idiot.

early on in the development process and before trying to scale, i had already reduced my output in the message handler. naturally, this omitted the required data:

def on_message(ws, message):
    my_msg = json.loads(message)
    if my_msg["type"] == "MESSAGE":

your suggestion is absolutely correct and will work. thank you so much for the prompt response and not tearing into me. :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.