tmijs / tmi.js

💬 Javascript library for the Twitch Messaging Interface. (Twitch.tv)
https://tmijs.com
MIT License
1.54k stars 217 forks source link

How to send chats to ejs template in node js ? #375

Closed abhayzonvoir closed 4 years ago

abhayzonvoir commented 4 years ago

How to send tmi js chat data to ejs template ? I integrated all the code in node js twitch api and tmi js and both working in server side(node js) but i want to display chat on frontend using ejs template. how to do it ??

please help me out.

this is my code, i call chats url from ajax from ejs template but i am not getting any response but in console all chats is visible.

router.get('/chats/', function(req, res){

const tmiClient = new tmi.client(options);

tmiClient.connect();
tmiClient.on('connected', onConnectedHandler);
var asdasd = tmiClient.on('message', function(target, context, msg, self){

    if (self) { return; } // Ignore messages from the bot

    // Remove whitespace from chat message
    const commandName = msg.trim();

    // If the command is known, let's execute it
    if(commandName === '!dice'){
    const num = rollDice();
    client.say(target, `You rolled a ${num}`);
    console.log(`* Executed ${commandName} command`);
    }else{
    console.log(`* Unknown command ${commandName}`);
    res.json({
       message: commandName
    });
    }

});

});

AlcaDesign commented 4 years ago

I don't understand why you would put tmi.js in a route handler the begin with. If you want to comminate between a frontend and a backend, you should use a real-time socket like socket.io. Alternatively you could just use tmi.js on the frontend.

abhayzonvoir commented 4 years ago

I want to show messages on frontend ejs template. How can i do it ? and how can i use tmi.js in frontend ?? I have no tmi.min.js

AlcaDesign commented 4 years ago

That's really not a tmi.js question.