How to send telegram message using JavaScript

Can anyone help me with the code to send telegram alert message using JavaScript…

1 Like

@vinayak.joshi, @rahul.singh1, @shoeb.ahmed, @PPV
I know you guys can help me out… with this problem.

Hi @Neeraj546,

Apologies for the delay. @shoeb.ahmed will look into this for you. I have brought it to his attention now.

1 Like

@Neeraj546 You will need to make an AJAX POST request to Telegram. The code should be similar to the one below.

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://api.telegram.org/" + telegram_bot_id + "/sendMessage",
  "method": "POST",
  "headers": {
    "Content-Type": "application/json",
    "cache-control": "no-cache"
  },
  "data": JSON.stringify({
    "chat_id": chat_id,
    "text": message
  })
}

$.ajax(settings).done(function (response) {
  console.log(response);
}); 

You will need to provide the telegram bot ID, chat ID and the message to be sent.

3 Likes

Sir I got an error like
$ is not defined…

Hi @Neeraj546,

Import the jquery in the head section of your HTML and then write/import you code for doing telegram alert.

<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
1 Like

Thank you so Much now its working…

1 Like