Hello!
I’m making a quiz app - guess the bird.
On command in the chat, Nightbot sends a request to the VPS server, where the app node.is should send a link to the picture of the bird to the chat.
And here’s the problem with printing a message to the chat.
I’m trying to get authorization for the application and send messages to the chat on YouTube…
{“access_token”:"*******a0b5f8431a84340a",“token_type”:“bearer”,“expires_in”:2592000,“refresh_token”:"ec10bb8619e31e983a79e913",“scope”:“me”}
And in the end I can’t type a message in the chat through the application.
Where to look, please tell me.
I only hope for your help. GPT doesn’t know anything.
function sendMessageToChat(message) {
const nightbotWebhookUrl = 'https://api.nightbot.tv/1/channel/send';
// Отправляем сообщение в чат с помощью вебхука
axios.post(nightbotWebhookUrl, null, {
params: {
message: message // Отправляем сообщение как параметр запроса
},
headers: {
'Authorization': `Bearer X`, // Подставь свой токен
'Content-Type': 'application/x-www-form-urlencoded' // Указываем тип контента
}
})
.then(response => {
console.log('Сообщение успешно отправлено в чат Nightbot');
})
.catch(error => {
console.error('Ошибка при отправке сообщения в чат:', error.response ? error.response.data : error.message);
});
}
Yes, I get a message that there is no authorization. In the end, I decided not to use a token at all and just send a message to the chat.
The message is sent, but the link is not active. And I wanted people from the chat to follow the link and write in the chat what kind of bird it is.
I’m struggling with how to make the link active.
I use this code.
// Отправка ссылки на изображение птички
app.get('/birdgame', (req, res) => {
currentBird = getRandomBird(); // Обновляем текущую птичку при каждом запросе
const host = req.hostname; // Получаем имя хоста
const port = req.socket.localPort; // Получаем порт, на котором работает сервер
// Формируем строку сообщения вместо объекта
//const message = `<a href="http://${host}:${port}/photo/${currentBird.image}">Отгадай, какая это птица!</a>`;
//const message = `http://${host}:${port}/photo/${currentBird.image}`;
//const message = `http://${host}:${port}/photo/${currentBird.image} Отгадай, какая это птица!`;
const message = `http://${host}:${port}/photo/${currentBird.image}`.trim();
// Отправляем строку, а не JSON
res.send(message);
//res.json({
// imageURL: `http://${host}:${port}/photo/${currentBird.image}`, // Формируем ссылку с портом
// message: 'Отгадай, какая это птица!'
//});
});
Maybe I don't need to get a token to write a message in the chat.
Now I would like to understand why the link in the chat is not active.
The code shows that I tried different options.
Maybe it's the night bot that doesn't allow you to insert links without authorization. I haven't figured it out yet(.