Here is my code :
const EXT_SECRET = Buffer.from('mYSecreT=', 'base64');
router.post('/message', (req, res) => {
const { channelId, clientId, userId } = req.body.auth;
fetch(`https://api.twitch.tv/extensions/message/${channelId}`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${makeServerToken(channelId, userId)}`,
'Client-Id': clientId,
'Content-Type': 'application/json'
},
body: JSON.stringify({
content_type: 'application/json',
message: { foo: 'bar' },
targets: ['broadcast']
})
})
.then(response => response.json())
.then(response => {
console.log(response);
})
.catch(err => { console.log(err) });
});
function makeServerToken(channelId, userId) {
const payload = {
exp: Math.floor(Date.now() / 1000) + 30,
channel_id: channelId.toString(),
user_id: userId.toString(),
role: 'external',
pubsub_perms: {
send: ['broadcast']
}
};
return jwt.sign(payload, EXT_SECRET, { algorithm: 'HS256' });
}
Here is the error I am getting:
{ error: 'Bad Request',
status: 400,
message: 'Missing required parameter "message"' }