I want to upload a .txt
file to telegram with my javascript bot.
I've seen a few examples in php and python but didn't understand, so I just need a js example to find out.
Should I upload a file first and then sendDocmuent
or should input in sendDocmuent
?
I've tried sendDocument
with document: 'file.txt'
but didn't work.
Also read about form-data but got nothing!
call("sendDocument",{
chat_id: owner,
document: 'file.txt' // or /file.txt or full address (C:...)
});
I'm not using any library, here is my call function:
const botUrl = "https://api.telegram.org/bot" + token + "/";
const request = require('request');
function call(method, params, onResponse)
{
var requestData = params;
var data = {
url: botUrl+method,
json: true,
body: requestData
};
request.post(data, function(error, httpResponse, body){
if (onResponse) {
if(body)
{
onResponse(body.result);
}
}
});
}