Extension Chat Message | Unauthorized 401

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

image

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

  • Has chat capabilities enabled
  • that version is installed
  • that version is active in one of the six slots
1 Like