Skip to content

Instantly share code, notes, and snippets.

@samermurad
Created January 10, 2020 17:59
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 samermurad/2f274764e9d7a83f4b8167b39c47b635 to your computer and use it in GitHub Desktop.
Save samermurad/2f274764e9d7a83f4b8167b39c47b635 to your computer and use it in GitHub Desktop.
Nodejs Request send Telegram Message through a bot
const requrest = require('request')
const BOT_TOKEN = '<YOUR_TOKEN_HERE>'
const CHAT_ID = 0 // <YOUR_CHAT_ID>
const tmMsg = (text) => {
const options = {
method: 'POST',
url: `https://api.telegram.org/bot${BOT_TOKEN}/sendMessage`,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ chat_id: CHAT_ID, text })
};
request(options, function (error, response) {
if (!error) //throw new Error(error);
console.log(response.body);
else console.log(error);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment