Hi, I don't know much in Javascript. Can I do this

to send Bot API method? Or there's another way better.

BotMethod('123456789:abcdEFGhimySElfQ', 'sendMessage', {
'chat_id' : '@PublicChannelUsername',
'text' : 'Hello World'
});

function BotMethod(botToken, method, data) {
var xmlHttp = new XMLHttpRequest();
const apiUrl = 'https://api.telegram.org/bot' + botToken + '/' + method;
xmlHttp.open("POST", apiUrl, true);
xmlHttp.send(data);
return xmlHttp.responseText;
}

P.S. I don't want to use any library, Because I'll use this in Browser.

2 ответов

23 просмотра

use fetch and asyncio. https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

𓂆 معاذ-القَرْني Автор вопроса

Thank you very much, It helped me a lot 😃

Похожие вопросы

Карта сайта