Skip to content

Instantly share code, notes, and snippets.

@AlirezaAkbarix
Created March 4, 2018 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlirezaAkbarix/5e1d6ba5125fbeb4347d647a73a939a3 to your computer and use it in GitHub Desktop.
Save AlirezaAkbarix/5e1d6ba5125fbeb4347d647a73a939a3 to your computer and use it in GitHub Desktop.
old method of using https for sending message via telegram
// Using old school method for sending message
const
https = require('https'),
reqOptions = {
method: 'POST',
hostname: 'api.telegram.org',
path: 'xxx',
headers: {
'Content-Type': 'application/json',
}
},
reqCallback = (res) => {
console.log(res.statusCode);
const chunkArr = [];
res.on(data, (chunk) => {
chunkArr.push(chunk);
});
res.on('end', () => {
const body = Buffer.concat(chunkArr);
console.log('body: ' + body.toString());
console.log('Connection closed!');
});
};
sendRequest = () => {
const req = https.request(reqOptions, reqCallback);
const reqBody = {
"chat_id": 73768632,
"text": "Hello World with my bot"
};
req.write(JSON.stringify(reqBody));
req.end();
};
sendRequest();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment