Chat Message from Extension


#1

I am trying to make chat functionality work for an extension I’m designing, but unfortunately I receive an error whenever the function is called:

HTTP505: VERSION NOT SUPPORTED - The server does not support, or refuses to support, the HTTP protocol version that was used in the request message.
(Fetch)GET - https://<CLIENT_ID>.ext-twitch.tv/<CLIENT_ID>/<VERSION_NUMBER>/<UNKNOWN_VALUE>/[object%20Object]

The function was derived from the one found at the bottom of the Chat Capabilities in Extensions post:

function chatMessage() {

    var url = "https://api.twitch.tv/extensions/" + onAuth.clientId + "/channels/" + onAuth.channelId + "/chat";
    var jwt = onAuth.token;
    var id = onAuth.clientId;
    var message = userID + " has purchased " + productName + ".";

    fetch({
        method: 'POST',
        url: url,
        headers: {
            'Content-Type': "application/json",
            'Client-ID': id,
            'Authorization': "Bearer " + jwt,
        },
        body: { text: message }
    }).catch ((err) => {
        console.log(err);
    });

}

The function is also being run from the broadcaster’s extension panel.

Thanks,
Michael


#2

Is wrong…

var url = "https://api.twitch.tv/extensions/" + onAuth.clientId + "/channels/" + onAuth.channelId + "/chat" seems to be incorrect in your code


#3

My mistake, I just checked and I was wrong about all that. What it SHOULD have been was:

(Fetch)GET - https://<CLIENT_ID>.ext-twitch.tv/<CLIENT_ID>/<VERSION_NUMBER>/<UNKNOWN_VALUE>/[object%20Object]

I’ll edit the post to reflect that.


#4

Then your URL construct is still wrong becuase it’s got an object on the end instead of chat.


#5

Okay, so after looking over some fetch documentation I solved the URL problem. It needed to be:

fetch(url, {
    method: 'POST',

instead of

fetch({
    method: 'POST',
    url: url,

But, now I get a 404 error from:

https://api.twitch.tv/extensions/<CLIENT_ID>/<VERSION>/channels/<CHANNEL_ID>/chat/pinned

and a 400 error from:

https://api.twitch.tv/extensions/<CLIENT_ID>/<VERSION>/channels/<CHANNEL_ID>/chat


#6

Pinned is not a valid end point.

Check the body for an error message that may assist


#7

Thanks…

The error was:

Request body was not parsable. Attempted Content-Type: "application/json"

Got standard chat messages to work by sending it stringified:

body: JSON.stringify({ text: message })

As far as /chat/pinned not being a valid end-point; has that functionality been removed, or changed since the article I mentioned in the original post?


#8

I don’t believe the pinned endpoint was ever official supported. The article you linked is an RFC, an announcement of what the plans/thoughts are at the time but doesn’t guarantee any of that will make it to the finished product, or without changes.

If you want to know what endpoints are supported and their requirements for use, refer to the docs as that is the definitive source of supported endpoints, not the forums.


#9

Thanks for the information. I had swore that I saw messages being pinned to a chat or two, but that must of been some other way. I’ll take another look over the docs sometime.


#10

Pinned messages are not a thing in vanilla chat at all.

Send a message to chat docs are here, I linked them earlier


#11

Thanks again.