Try
let tokenPayload = {
exp: Math.floor(new Date().getTime() / 1000) + 60,
channel_id: ''+channel,
role: 'external',
pubsub_perms: {
send: [
'broadcast'
]
}
}
let pck = {
message: JSON.stringify(payload),
content_type: 'application/json',
targets: tokenPayload.pubsub_perms.send
}
let signedJwt = jwt.sign(tokenPayload, secret);
request.post({
url: 'https://api.twitch.tv/extensions/message/' + channel,
headers: {
Authorization: 'Bearer ' + signedJwt,
'Client-ID': client_id,
'Content-Type': 'application/json'
},
body: JSON.stringify(pck),
gzip: true
}, function(e, r, b) {
if (e) {
console.log(e);
} else if (r.statusCode == 204) {
console.log('Ok');
} else {
console.log('Failed');
console.log(b);
}
});
or equivalent, instead.
This is what I’m using on production without issue.
I think just your targets are wrong, should be broadcast instead of *
The example is
{
"exp": 1503343947,
"user_id": "27419011",
"role": "external",
"channel_id": "27419011",
"pubsub_perms": {
"send":[
"broadcast"
]
}
}