Send Extension PubSub Message: works on my channel, but not others (solved)

Hi all!

I’ve been working on an extension where my EBS sends a message via the broadcast topic of a certain channel so that the extensions can be notified of events.
This has worked flawlessly while testing on my own channel, but when I attempt to send the broadcast pubsub message to another channel (changing the channelid when generating JWT) it doesn’t seem to work. The request itself returns a 204 response indicating a success, but the message is never received by the extension on that channel.
I wrote a separate application to listen to the broadcast topic (channel-ext-v1.<channel_id>-<extension_id>-broadcast, thanks ModestTim). Listening on my channel, i see the data come in as expected. When listing to another channel (that has the extension installed), no messages are ever received.

Is there something I need to do to allow my EBS to publish broadcast pubsub messages to a channel other than my own?

Thanks!

1 Like
var tokenPayload = {
    exp: Math.floor(new Date().getTime() / 1000) + 60,
    channel_id: ''+channel,
    role: 'external',

    pubsub_perms: {
        send: [
            'broadcast'
        ]
    }
}

let signedJwt = jwt.sign(tokenPayload, SECRET);

request.post({
    url: 'https://api.twitch.tv/v5/extensions/message/' + channel,
    headers: {
        Accept: 'application/vnd.twitchtv.v5+json',
        Authorization: 'Bearer ' + signedJwt,
        'Client-ID': CLIENT,
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        message: payload,
        content_type: 'application/json',
        targets: ['broadcast']
    }),
    gzip: true
}, function(e, r, b) {
    if (e) {
        console.log(e);
    } else if (r.statusCode == 204) {
        console.log('Ok to ' + channel);
    } else {
        console.log('Got ' + r.statusCode + ' to ' + channel);
        console.log(b);
    }
});

You did change the channelID in your signedJWT and the URL you post to right?

Check the example ->

The ChannelID is in the signedJWT and in the URL you POST to.

Seems you shouldn’t get a 204 if the JWT is valid but doesn’t match the ChannelID you are POSTing to.

You sent a valid JWT for the wrong channel?

I just realized I had a hard coded channel Id in one of the several places you put the channel Id.

I feel like an idiot, sorry for wasting your time.

Quack

3 Likes