> For the complete documentation index, see [llms.txt](https://xn--6o0a585a.gitbook.io/devops/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xn--6o0a585a.gitbook.io/devops/telegram-ji-qi-ren/javacript-chuang-jian-xin-xi-tui-song-ye-mian.md).

# Javacript创建信息推送页面

![](/files/j1Ckf8PsQgn0B2ww2GyR)

### 1.初步尝试js调用TGbot机器人 <a href="#title-0" id="title-0"></a>

目录：

```
index.html
script.js
```

首先写个简单的Send发送按钮

```html
<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<title>Telegramm Bot</title>
</head>
<body>
		<input type="text" class="chatID" placeholder="请输入chatID"><br>
    	<input type="text" class="message" placeholder="输入要推送的信息"><br>
		<button>发送</button>
<script src="script.js"></script>
</body>
</html>
```

然后编写`script.js`代码

```javascript
document.querySelector('button').onclick = () => {
	
	const token = '1024523851:AAHozZ3P5XVtd100PutbD7MY11Lx6MAqNfg';
    let chatID = document.querySelector('.chatID').value;
    let messageTB = document.querySelector('.message').value;
	const url = `https://api.telegram.org/bot${token}/sendMessage?chat_id=${chatID}&text=`;
	
	let xhttp = new XMLHttpRequest();;
	xhttp.open('GET',url+messageTB, true);
	xhttp.send();
}
```

运行效果如下：

![Telegram机器人：用Javacript创建信息推送页面](https://cdn.jsdelivr.net/gh/Baiyuetribe/yyycode@dev/img/20/5e00bc13e1270.jpg)

### 2.逐步完善一下后 <a href="#title-1" id="title-1"></a>

代码如下：

```php
<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<title>Telegramm Bot</title>
</head>
<style>
.message{
    padding: 6px;
    width: 100%;
    margin-bottom: 25px;
    height: 90px;
    border: 1px solid #3f51b5;
    font-size: large;
}
.chatID{
    width: 100%;
    margin-bottom: 25px;
    border: 1px solid #3f51b5;
    font-size: large;
    height: 30px; 
}
.token{
    width: 100%;
    margin-bottom: 25px;
    border: 1px solid #3f51b5;
    font-size: large;
    height: 30px; 
}
.container{
    width: 460px;
    margin: 24px auto 0;
    padding: 25px 65px;
    border: 1px dashed rgb(133, 101, 101);
    border-radius: 15px;
    background: #fff;
}
h1{
    text-align: center;
}
button{
    padding: 1em 2em;
    background-color: #3F51B5;
    color: #fff;
    border-radius: 4px;
    border: none;
    position: relative;
    transition: transform ease-in 0.1s, box-shadow ease-in 0.25s;
    box-shadow: 0 2px 25px #3F51B5;
    display: block;
    margin: 0 auto;
    width: inherit;
}
</style>
<body>
    <div class="container">
            <h1>TG机器人发信测试</h1>
            <input type="text" class="message" placeholder="输入要推送的信息"><br>
            <button>发送</button>
            <p>一些设置：</p>
            <p>发送信息的聊天ID，或者群组名称，示例@BaiyueGroup</p>
            <input type="text" class="chatID" placeholder="请输入chatID"><br>
            <p>填写您的机器人令牌</p>
            <input type="text" class="token" placeholder="请输入机器人令牌Token"><br>
    </div>
    	
<script>
    
document.querySelector('button').onclick = () => {
    let token = document.querySelector('.token').value;
	//const token = '1024523851:AAHozZ3P5XVtd100PutbD7MY11Lx6MAqNfg';
    let chatID = document.querySelector('.chatID').value;
    let messageTB = document.querySelector('.message').value;
	const url = `https://api.telegram.org/bot${token}/sendMessage?chat_id=${chatID}&text=`;
	
	let xhttp = new XMLHttpRequest();;
	xhttp.open('GET',url+messageTB, true);
	xhttp.send();
}    
</script>
</body>
</html>
```

最终效果如开篇截图那样。

### 3.小评 <a href="#title-2" id="title-2"></a>

这是个人学习TG机器人，初步尝试的产品，虽然再shell命令行和python里有更多扩展，但是最方便入手的，肯定比不上这种单一页面组成的程序。所以，JavaScript还是有必要多学习下。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xn--6o0a585a.gitbook.io/devops/telegram-ji-qi-ren/javacript-chuang-jian-xin-xi-tui-song-ye-mian.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
