I am having troubles trying to send Chat Message from my EBS.
I think it’s something to do with the JWT, but I am not sure (I read the Docs a few times).
I keep getting Unauthorized 401.
Signed JWT created by the EBS, following the requirements documented in Signing the JWT (in Building Extensions ) or Twitch JWT containing the broadcaster role. The channel_id inside the JWT must match the channel ID in the request URL.
Signed JWT created by the EBS, following the requirements documented in Signing the JWT (in Building Extensions ) or Twitch JWT containing the broadcaster role. The channel_id inside the JWT must match the channel ID in the request URL.
But doesn’t it means that I need to use a JWT that I sign on my EBS (and according to the docs in “Building Extensions” it means to use “role”: “external”), OR to use a different Twitch JWT that already contains the broadcaster role?
const fs = require('fs');
const request = require('request');
const jwt = require('jsonwebtoken');
let twitch_id = 'destination_channel_id';
let version = '0.0.1';
var secret = Buffer.from(secret, 'base64');
var payload = {
'exp': Math.floor(new Date().getTime() / 1000) + 60,
'user_id': ''+twitch_id,
'role': 'broadcaster'
}
var sig = jwt.sign(payload, secret);
// tell everyone
var payload = JSON.stringify({
'text': 'Test'
});
let url = 'https://api.twitch.tv/extensions/'
+ client_id + '/'
+ version
+ '/channels/'
+ twitch_id
+ '/chat';
request.post({
url: url,
headers: {
'Accept': 'application/vnd.twitchtv.v5+json',
'Authorization': 'Bearer ' + sig,
'Client-ID': client_id,
'Content-Type': 'application/json'
},
body: payload,
gzip: true
}, function(e, r, b) {
if (e) {
console.log(e);
} else if (r.statusCode == 204) {
console.log('Relay chat OK');
} else {
console.log('Got ' + r.statusCode);
console.log(b);
}
});
Worked for me
It is worth noting, that I was getting auth errors till I reliased, I was sending to a channel that did not have the (in this case) panel in an active slot.
Please check that the extension version you are testing with