Send Chat message

Hello :slight_smile: i try to send a chat message but i get a 404 error with this code

function chatMessage() {
    var url = "https://api.twitch.tv/extensions/" + clientId + "/0.0.1/channels/" + channelID + "/chat";
    console.log(url);
    var jwt = token;
    var id = clientId;
    var message = "test";

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

You have tried to use the old URL for this API

Please see the updated documentation

For the URL and payload changes

Or an example: https://github.com/BarryCarlyon/twitch_misc/tree/main/extensions/chat

I still get 404 with the following code

function chatMessage() {
    var url = "https://api.twitch.tv/helix/extensions/chat?broadcaster_id=" + channelID;
    console.log(url);
    var jwt = token;
    var id = clientId;
    var message = "test";

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

i changed only the url

is the extension installed and active on the text channel?

If you check the body of the response it will help describe the issue

its right now in local testing. But its installed and the option for chat support in the dev console is set to yes

Uninstall the extension from the channel
And install it and activate it into a slot again, in case the permission isn’t enabled right

image

Then under manage permissions in the dashboard check the chat toggle is enabled

Then if it doesn’t work

Check the HTTP Body of the response, not just the HTTP Code

Also jsut realised your body is incomplete.

For Example:

fetch(
    "https://api.twitch.tv/helix/extensions/chat",
    {
        method: "POST",
        headers: {
            "Client-ID": config.client_id,
            "Authorization": "Bearer " + sigChat,
            "Content-Type": 'application/json'
        },
        body: JSON.stringify({
            broadcaster_id: config.channel_id,
            text: "This is a Test Message Kappa",
            extension_id: config.client_id,
            extension_version: config.extension_version
        })
    }
)
1 Like

Thanks its working right now! :slight_smile: I think this was my last question for now

I was looking in the documentation but i wasnt able to find something. Is it possible to highlite the message my extension is sending?

There are no options all you get is

image

For example

oh ok :slight_smile: thanks

ok something wired happend. I used the code from yesterday and the extension will send the chat message when i use the extension with the Brodcaster account. But if i log on a other account i get this error

POST https://api.twitch.tv/helix/extensions/chat 401

Only the Broadcaster, or your EBS using a JWT you create/sign, can send Extension chat messages. Otherwise there would be nothing stopping any user from attempting to send malicious chat messages as your Extension.

ah ok :slight_smile: so i need to send the message from something like a chatbot right ?

Either your EBS using the Send Chat endpoint
Or a chatbot

Which is basically the same thing in this scenario

Since you’ll need to get the event from the extension to your backend.
Then your backend can send it out on whatever your preference is

hmm is there any irc libary which i can use to send the chat message ? for the other soulution you mean this end point [Preformatted text](https://api.twitch.tv/helix/extensions/chat) right?

many

Yes the endpoint you were using throughout this post

can you recommend one?

I don’t use libraries for IRC, so no. since I don’t use any.

ok i got it now via the irc. But is there also a way to get the oauth token for my chat bot account automaticly ? right now i just was creating one manual