Created
March 4, 2018 02:57
-
-
Save AlirezaAkbarix/5e1d6ba5125fbeb4347d647a73a939a3 to your computer and use it in GitHub Desktop.
old method of using https for sending message via telegram
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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