Send message from website to telegram bot through javascript

Send website message to telegram chatbot using javascript api

In this article we will learn a way by which we can send the website query data or website contact form data directly to the telegram chatbot, through the simple javascript API method we can Send website query to telegram bot, To achive this we are going to create simple constact form or a website query from and on submit of that we will validate and Send message from website to telegram bot through javascript,

This is the same process as we send the user query to the website query email so the website admin can resolve the user query and get in tough with them.

In this project we simply need to create a contact form in html and we need to play with telegram chatbot api, to access the telegram API we need to get the API access from Telegram BotFather, let understand somethign about telegram BotFather

What is Telegram BotFather

Telegram BotFather is the admin of all your bot, thought this you can manage all your bots and able to get the authentication to that perticuler bot on other word, It is a special bot on the telegram messaging platform that allow users to create and manage the other bots

How to create new bot in telegram

Below are the steps by which you can create a new bot in telegram

1. Go to you search in telegram and type BotFather as shown in image below.

website query to telegram bot through javascript

2. Now open BotFather and type  /newbot in message and press enter input as shown in image below

Telegram BotFather screen

3. When you send the above command then as a chatbot response it will ask for new bot name as shown below

Telegran Create new bot

After entering the name it will ask for the new username for the chatbot as shown in beow image, also it will show the below message and you need to take care your user name must contain the bwlo nameing format
Good. Now let’s choose a username for your bot. It must end in bot. Like this, for example: TetrisBot or tetris_bot.

4. After entering the username you weill see the response as shown in below image

Telegran get ne api toket fro new bot

By above steps you can create a new bot in telegram , the BotFather also provided the Authentication token which you can see in above image that is bllured for security resons, Now we will learn how we can Send website query to telegram bot

Send website query to telegram bot

To send query to the chatbot we must need the chat id for that, and to know your chat id you need to send nessage to your chatbot as shown in image below.

telegran new bot send message

Once you send message you neew to hit simple below api url

https://api.telegram.org/bot<YourApiToken>getUpdates
telegram how to get chat id

In above image highlighted one is chat id.

Now you will got the chat id and API toke , so by using the chat id and token we can send website query to chat bot

In above code we have stored the below variable

token: Stores the bot token.
chatId: Stores the chat ID.
textMessage: Stores the message text.

Also if you can to send some picture by uploading in to the form data you can also do so by using below code

Further reading

  • React UseEffect | simplifyScript

    Understanding the useEffect hook in React

    In this article, we will learn about another React hook called useEffect(), through this article you will be able to understand what is react useEffect Hook and how to use useEffect() hook in react, this is most communally used hook after useState() hook, we mostly use this hook in every component on react now first […]
  • React useState function

    How to Use useState Hook in React Application

     In a React application, normal vanilla JavaScript may not work for some concepts. For example, if I want to toggle a class on a button click or add and remove classes, I might need to show a popup on the website. This can be easily achieved in vanilla JavaScript using the element.classList.toggle(“newClass”) method, allowing us to add […]
  • javascript DOm manipulation - simplifyscript

    What is DOM manipulation in javascript 

    In this article, we will explore JavaScript DOM manipulation, a key feature of JavaScript that allows developers to modify the Document Object Model (DOM) of a webpage. DOM manipulation enables you to dynamically alter the content and structure of HTML documents. To grasp this concept thoroughly, we’ll start by defining what the DOM is and […]