Check that channelId is a “string” and not a “number” so
channelId = '123';
and not
channelId = 123;
Check that you did base64 decode the token first before use?
Check that Chat is “enabled” on the extension in the console.
Your payload
body: textToBeSentToChat
is unclear and may not match the request to send as documented
Where is the rest of the call?
Here is an “up to date script” using the new API, use got for communications
`use strict`;
const fs = require('fs');
const path = require('path');
let config = {
"client_id": "REMOVED",
"extension_secret": "REMOVED",
"owner_id": "15185913",
"version": "REMOVED"
}
let broadcaster_id = 'REMOVED';
const jwt = require('jsonwebtoken');
const got = require('got');
const secret = Buffer.from(config.extension_secret, 'base64');
let sigPayload = {
'exp': Math.floor(new Date().getTime() / 1000) + 4,
'user_id': config.owner_id,
'role': 'external'
}
let sig = jwt.sign(sigPayload, secret);
got({
url: 'https://api.twitch.tv/helix/extensions/chat',
method: 'POST',
headers: {
'Client-ID': config.client_id,
'Authorization': 'Bearer ' + sig,
'Content-Type': 'application/json'
},
searchParams: {
broadcaster_id
},
body: JSON.stringify({
text: 'Test Message',
extension_id: config.client_id,
extension_version: config.version
}),
responseType: 'json'
})
.then(resp => {
console.log('Result', resp.statusCode, resp.body, resp.headers['ratelimit-remaining'], '/', resp.headers['ratelimit-limit']);
})
.catch(err => {
if (err.response) {
console.error('API ERROR', err.response.statusCode, err.response.body);
return;
}
console.error('BAD ERROR', err);
});
