Can't Listen to Extension PubSub Whispers

Attempting to listen to pubsub messages via window.twitch.ext.listen('whisper-<user-id>', callback) returns ERR_BADAUTH. Tried it with opaque_user_id as well but that also shows the same error. Am I missing something?
I don’t see whisper included in pubsub_perms.listen, is this why I’m getting the error?
image
image

You need to listen on

Whispers are a set of optional PubSub channels that extensions can use. Each copy of an extension can register for "whisper-<userId>" where userId comes from the onAuthorized message. Attempts to listen to another userId will be blocked.

Where the userID is returned in onAuthorized and is the Opaque user ID. not the actual users Twitch UserID.

More on OpaqueId’s


Still getting the error with the opaque user id.

I tested

window.Twitch.ext.listen(window.Twitch.ext.viewer.opaqueId, (t,c,m) => {
});

And didn’t get a bad Auth.

EDIT: ABOVE IS INCORRECT should be

window.Twitch.ext.listen(‘whisper-’+window.Twitch.ext.viewer.opaqueId, (t,c,m) =&gt; { });

Thanks! That seems to work for me as well.
I was trying to listen on "whisper-<userId>" as per the documentation, but the correct topic for whispers seems to be just the "<userId>" where userId is opaque id of the current user.

Errr

Thats a point. it’s supposed to be whisper-<userID>

My code is wrong

it’s

window.Twitch.ext.listen(‘whisper-’+window.Twitch.ext.viewer.opaqueId, (t,c,m) => { });

Which I also didn’t get a Err BadAuth on, this the topic is

whisper-<userID>' where ` is the Opaque UserID

Ok, “whisper-” also works for me. I realized i was setting up the listener before the onAuthorized callback. I guess that’s why I was getting BAD_AUTH. Thanks for the help!

Yup that’ll do it.

onAuthorised has to trigger first as then the extension system is ready to go, and if you don’t wait for onAuthorised, then you don’t have the right opaqueID

1 Like

Still having trouble with listening for whisper messages. When i try to send a message by posting to the pubsub endpoint, it goes through but im not seeing the message come up on client side.
Looking at websocket connections, i see that attempt to connect may have been unsuccessful. Again, this is when using window.twitch.ext.listen.

I can’t replicate the issue.

Can you provide your front end code to poke about in to see whats going on?

var twitch = window.Twitch.ext

twitch.onAuthorized(auth => {
  if (auth.token) {

      twitch.listen('whisper-'+auth.userId, (e, c, t)=>{
        console.log(e,c,t)
      })

  }
})

Its essentially just this wrapped in a react context.