Full Code of anhao/TgMessage for AI

main 8ce2fbac680b cached
16 files
60.1 KB
17.2k tokens
19 symbols
1 requests
Download .txt
Repository: anhao/TgMessage
Branch: main
Commit: 8ce2fbac680b
Files: 16
Total size: 60.1 KB

Directory structure:
gitextract_com7y8vo/

├── .edgeone/
│   └── project.json
├── .gitignore
├── LICENSE
├── README.md
├── api/
│   ├── Bot.php
│   ├── index.php
│   ├── setWebHook.php
│   └── webhook.php
├── edge_deploy/
│   └── edge.html
├── edgeone.json
├── functions/
│   ├── bot.js
│   ├── sendMessage.js
│   ├── setWebhook.js
│   └── webhook.js
├── index.html
└── vercel.json

================================================
FILE CONTENTS
================================================

================================================
FILE: .edgeone/project.json
================================================
{
  "Name": "tg-message",
  "ProjectId": "pages-ywhm4l7gjx2i"
}

================================================
FILE: .gitignore
================================================
.vercel
.idea
.idea/
# Tencent Cloud EdgeOne
.env
.edgeone/*
!.edgeone/project.json
.tef_dist/*
  

================================================
FILE: LICENSE
================================================
                        Apache License
                           Version 2.0, January 2004
                        http://www.apache.org/licenses/

   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

   1. Definitions.

      "License" shall mean the terms and conditions for use, reproduction,
      and distribution as defined by Sections 1 through 9 of this document.

      "Licensor" shall mean the copyright owner or entity authorized by
      the copyright owner that is granting the License.

      "Legal Entity" shall mean the union of the acting entity and all
      other entities that control, are controlled by, or are under common
      control with that entity. For the purposes of this definition,
      "control" means (i) the power, direct or indirect, to cause the
      direction or management of such entity, whether by contract or
      otherwise, or (ii) ownership of fifty percent (50%) or more of the
      outstanding shares, or (iii) beneficial ownership of such entity.

      "You" (or "Your") shall mean an individual or Legal Entity
      exercising permissions granted by this License.

      "Source" form shall mean the preferred form for making modifications,
      including but not limited to software source code, documentation
      source, and configuration files.

      "Object" form shall mean any form resulting from mechanical
      transformation or translation of a Source form, including but
      not limited to compiled object code, generated documentation,
      and conversions to other media types.

      "Work" shall mean the work of authorship, whether in Source or
      Object form, made available under the License, as indicated by a
      copyright notice that is included in or attached to the work
      (an example is provided in the Appendix below).

      "Derivative Works" shall mean any work, whether in Source or Object
      form, that is based on (or derived from) the Work and for which the
      editorial revisions, annotations, elaborations, or other modifications
      represent, as a whole, an original work of authorship. For the purposes
      of this License, Derivative Works shall not include works that remain
      separable from, or merely link (or bind by name) to the interfaces of,
      the Work and Derivative Works thereof.

      "Contribution" shall mean any work of authorship, including
      the original version of the Work and any modifications or additions
      to that Work or Derivative Works thereof, that is intentionally
      submitted to Licensor for inclusion in the Work by the copyright owner
      or by an individual or Legal Entity authorized to submit on behalf of
      the copyright owner. For the purposes of this definition, "submitted"
      means any form of electronic, verbal, or written communication sent
      to the Licensor or its representatives, including but not limited to
      communication on electronic mailing lists, source code control systems,
      and issue tracking systems that are managed by, or on behalf of, the
      Licensor for the purpose of discussing and improving the Work, but
      excluding communication that is conspicuously marked or otherwise
      designated in writing by the copyright owner as "Not a Contribution."

      "Contributor" shall mean Licensor and any individual or Legal Entity
      on behalf of whom a Contribution has been received by Licensor and
      subsequently incorporated within the Work.

   2. Grant of Copyright License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      copyright license to reproduce, prepare Derivative Works of,
      publicly display, publicly perform, sublicense, and distribute the
      Work and such Derivative Works in Source or Object form.

   3. Grant of Patent License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      (except as stated in this section) patent license to make, have made,
      use, offer to sell, sell, import, and otherwise transfer the Work,
      where such license applies only to those patent claims licensable
      by such Contributor that are necessarily infringed by their
      Contribution(s) alone or by combination of their Contribution(s)
      with the Work to which such Contribution(s) was submitted. If You
      institute patent litigation against any entity (including a
      cross-claim or counterclaim in a lawsuit) alleging that the Work
      or a Contribution incorporated within the Work constitutes direct
      or contributory patent infringement, then any patent licenses
      granted to You under this License for that Work shall terminate
      as of the date such litigation is filed.

   4. Redistribution. You may reproduce and distribute copies of the
      Work or Derivative Works thereof in any medium, with or without
      modifications, and in Source or Object form, provided that You
      meet the following conditions:

      (a) You must give any other recipients of the Work or
          Derivative Works a copy of this License; and

      (b) You must cause any modified files to carry prominent notices
          stating that You changed the files; and

      (c) You must retain, in the Source form of any Derivative Works
          that You distribute, all copyright, patent, trademark, and
          attribution notices from the Source form of the Work,
          excluding those notices that do not pertain to any part of
          the Derivative Works; and

      (d) If the Work includes a "NOTICE" text file as part of its
          distribution, then any Derivative Works that You distribute must
          include a readable copy of the attribution notices contained
          within such NOTICE file, excluding those notices that do not
          pertain to any part of the Derivative Works, in at least one
          of the following places: within a NOTICE text file distributed
          as part of the Derivative Works; within the Source form or
          documentation, if provided along with the Derivative Works; or,
          within a display generated by the Derivative Works, if and
          wherever such third-party notices normally appear. The contents
          of the NOTICE file are for informational purposes only and
          do not modify the License. You may add Your own attribution
          notices within Derivative Works that You distribute, alongside
          or as an addendum to the NOTICE text from the Work, provided
          that such additional attribution notices cannot be construed
          as modifying the License.

      You may add Your own copyright statement to Your modifications and
      may provide additional or different license terms and conditions
      for use, reproduction, or distribution of Your modifications, or
      for any such Derivative Works as a whole, provided Your use,
      reproduction, and distribution of the Work otherwise complies with
      the conditions stated in this License.

   5. Submission of Contributions. Unless You explicitly state otherwise,
      any Contribution intentionally submitted for inclusion in the Work
      by You to the Licensor shall be under the terms and conditions of
      this License, without any additional terms or conditions.
      Notwithstanding the above, nothing herein shall supersede or modify
      the terms of any separate license agreement you may have executed
      with Licensor regarding such Contributions.

   6. Trademarks. This License does not grant permission to use the trade
      names, trademarks, service marks, or product names of the Licensor,
      except as required for reasonable and customary use in describing the
      origin of the Work and reproducing the content of the NOTICE file.

   7. Disclaimer of Warranty. Unless required by applicable law or
      agreed to in writing, Licensor provides the Work (and each
      Contributor provides its Contributions) on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
      implied, including, without limitation, any warranties or conditions
      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
      PARTICULAR PURPOSE. You are solely responsible for determining the
      appropriateness of using or redistributing the Work and assume any
      risks associated with Your exercise of permissions under this License.

   8. Limitation of Liability. In no event and under no legal theory,
      whether in tort (including negligence), contract, or otherwise,
      unless required by applicable law (such as deliberate and grossly
      negligent acts) or agreed to in writing, shall any Contributor be
      liable to You for damages, including any direct, indirect, special,
      incidental, or consequential damages of any character arising as a
      result of this License or out of the use or inability to use the
      Work (including but not limited to damages for loss of goodwill,
      work stoppage, computer failure or malfunction, or any and all
      other commercial damages or losses), even if such Contributor
      has been advised of the possibility of such damages.

   9. Accepting Warranty or Additional Liability. While redistributing
      the Work or Derivative Works thereof, You may choose to offer,
      and charge a fee for, acceptance of support, warranty, indemnity,
      or other liability obligations and/or rights consistent with this
      License. However, in accepting such obligations, You may act only
      on Your own behalf and on Your sole responsibility, not on behalf
      of any other Contributor, and only if You agree to indemnify,
      defend, and hold each Contributor harmless for any liability
      incurred by, or claims asserted against, such Contributor by reason
      of your accepting any such warranty or additional liability.

   END OF TERMS AND CONDITIONS

   APPENDIX: How to apply the Apache License to your work.

      To apply the Apache License to your work, attach the following
      boilerplate notice, with the fields enclosed by brackets "[]"
      replaced with your own identifying information. (Don't include
      the brackets!)  The text should be enclosed in the appropriate
      comment syntax for the file format. We also recommend that a
      file or class name and description of purpose be included on the
      same "printed page" as the copyright notice for easier
      identification within third-party archives.

   Copyright [yyyy] [name of copyright owner]

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.


================================================
FILE: README.md
================================================
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https%3A%2F%2Fgithub.com%2Fanhao%2FTGMessage)
[![Deploy to PandaStack](https://dashboard.pandastack.io/deploy-button.svg)](https://dashboard.pandastack.io/deploy?repo=anhao/TgMessage&type=static&buildCmd=npm+run+build&outputDir=dist)

[![使用 EdgeOne Pages 部署](https://cdnstatic.tencentcs.com/edgeone/pages/deploy.svg)](https://edgeone.ai/pages/new?repository-url=https%3A%2F%2Fgithub.com%2Fanhao%2FTGMessage&project-name=tg-message&build-command=&install-command=&output-directory=edge_deploy&root-directory=./&env=token,sign_key&env-description=)

## 技术赞助

本项目 CDN 加速及安全防护由 Tencent EdgeOne 赞助:EdgeOne 提供长期有效的免费套餐,包含不限量的流量和请求,覆盖中国大陆节点,且无任何超额收费,感兴趣的朋友可以点击下面的链接领取

[亚洲最佳CDN、边缘和安全解决方案 - Tencent EdgeOne](https://edgeone.ai/zh?from=github&utm_source=TgMessage)


<a href="https://edgeone.ai/?utm_source=TgMessage">
  <img width="200" src="https://edgeone.ai/media/34fe3a45-492d-4ea4-ae5d-ea1087ca7b4b.png" alt="Tencent EdgeOne">
</a>

## 第一步:创建 Telegram 机器人 (公共教程)

在部署之前,您首先需要一个 Telegram Bot。

1.  **关注 BotFather**: 在 Telegram 中搜索并关注官方的 [BotFather](https://t.me/BotFather)。
2.  **创建机器人**: 
    *   向 BotFather 发送 `/newbot` 命令。
    *   根据提示,依次输入机器人的显示名称(例如 `我的消息助手`)和用户名(必须以 `bot` 结尾,例如 `my_message_assistant_bot`)。
    ![oEENc.png](/img/img.png)
3.  **获取 Token**: 创建成功后,BotFather 会发送一条包含 **API Token** 的消息。请务必保存好这个 Token,它在后续部署中是必需的。
    ![oEGEr.png](/img/img_1.png)
4.  **设置命令**: 为了方便获取 `chat_id`,需要为机器人设置一个命令。
    *   向 BotFather 发送 `/mybots`,然后选择你刚刚创建的机器人。
    *   点击 `Edit Bot` -> `Edit Commands`。
    *   输入 `token - 获取个人 Token` 并发送。
    ![oEQIM.png](/img/img_2.png)

---

## 第二步:选择平台进行部署

您可以选择 Vercel 或 腾讯云 EdgeOne 进行部署,两者择一即可。

### 选项 A:通过 Vercel 部署

Vercel 提供免费、快速的 Serverless 函数托管服务。

1.  **一键部署**: 点击项目顶部的 **Deploy with Vercel** 按钮。
2.  **设置环境变量**: 在 Vercel 的项目创建页面,你需要配置以下环境变量:
    *   `token`: **【必填】** 填入上一步获取的机器人 API Token。
    *   `sign_key`: **【建议】** 用于加密 `chat_id` 的密钥,不设置默认为 `abc`。建议设置为一个复杂的随机字符串。
    *   `key`: **【建议】** 设置 Webhook 时的管理密钥,防止他人调用。请设置为一个复杂的随机字符串。
    *   `url`: **【可选】** 你的 Webhook 回调地址。如果不设置,后续需要手动指定。Webhook 最终地址为 `https://<你的Vercel域名>/api/webhook`。
    ![oSJRB.png](/img/img_12.png)
3.  **获取个人 Token**:
    *   部署完成后,在浏览器中访问 `https://<你的Vercel域名>/api/setWebhook?key=<你设置的key>` 来设置回调。
    *   然后与你的机器人对话,发送 `/token` 命令,机器人会返回一长串加密的个人 Token。
4.  **发送消息**:
    *   现在你可以通过请求 `https://<你的Vercel域名>/api/index?token=<你的个人Token>&message=你好` 来给自己发送消息。

### 选项 B:通过 EdgeOne Page Functions 部署

EdgeOne 是腾讯云推出的边缘一体化安全与加速平台,其 Page Functions 功能同样可以托管本项目。
![edge_image](/img/edge_image_1.png)
1.  **一键部署 (推荐)**:
    *   点击项目顶部的 **使用 EdgeOne Pages 部署** 按钮。
    *   授权后,在项目创建页面,EdgeOne 会自动为你填充大部分配置。
    *   在 **环境变量** 部分,填入 `token` 和 `sign_key`。
    *   **重要**: 部署启动后,请立即进入项目 "设置" -> "环境变量" 页面,**手动添加**第三个环境变量 `key`。
    *   **环境变量说明**:
        *   `token`: **【必填】** 你的 Telegram Bot Token。
        *   `sign_key`: **【必填】** 加密 `chat_id` 用的密钥。
        *   `key`: **【必填】** 设置 Webhook 用的管理密钥。
2.  **手动部署**:
    *   Fork 本项目到你的 GitHub 账户。
    *   在 EdgeOne 控制台新建 Pages 项目,关联你 Fork 的仓库。
    *   **输出目录** 填写 `edge_deploy`。
    *   手动添加上述三个环境变量。
3.  **获取个人 Token**:
    *   部署成功后,在浏览器中访问 `https://<你的Pages域名>/setWebhook?key=<你设置的key>` 设置回调。
    *   与你的机器人对话,发送 `/token` 命令,获取个人 Token。
4.  **发送消息**:
    *   通过访问 `https://<你的Pages域名>/sendMessage?token=<你的个人Token>&message=你好` 发送消息。
    *   API 详情可参考 `edge_deploy/edge.html`。

## Vercel 版本

TG 消息推送机器人,基于 vercel 函数 和 Edgeone 边缘函数 搭建的TG消息推送机器人,无需服务器。

## 搭建教程
### Deploy to Vercel
[![Deploy to Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https%3A%2F%2Fgithub.com%2Fanhao%2FTgMessage&env=token,sign_key,key&project-name=tg-message&repo-name=tg-message&demo-title=TG%20Message&demo-url=https%3A%2F%2Ftg-message.vercel.app%2F)
[![Deploy to PandaStack](https://dashboard.pandastack.io/deploy-button.svg)](https://dashboard.pandastack.io/deploy?repo=anhao/TgMessage&type=static&buildCmd=npm+run+build&outputDir=dist)
### 建立 TG 机器人

1.首先关注 [BotFather](https://t.me/BotFather)

2. 创建机器人,关注 BotFather 之后,发送 `/newboot` 开始创建 Bot 第一次输入机器人名称,第二次输入机器人 `username` 需要以 `bot` 结尾
   ![oEENc.png](/img/img.png)

**3.获取机器人 token**

创建成功之后会发送一条消息给你,里面就包含了 `token`

![oEGEr.png](/img/img_1.png)

**设置机器人 Command**
设置获取 token 命令 首先给 BotFather 发送 `/mybots`,然后点击你刚才创建的机器人,再点击 `Edit Bot`, 继续点击 `Edit Commands`。 然后输入

```
token - 获取token
```

这样就设置好了一个 `commands`

![oEQIM.png](/img/img_2.png)
![oE0FG.png](/img/img_3.png)
![oEcR1.png](/img/img_4.png)
![oEd9I.png](/img/img_5.png)


## 部署到 Vercel

点击首页的 Deploy 跳到 vercel
![oSgul.png](/img/img_10.png)

输入项目名,然后确认

![oSpFg.png](/img/img_11.png)

确认之后会直接部署到 vercel

### 设置环境变量

vercel 部署好了之后,然后设置环境变量

在控制台点击你创建好的项目,然后点击设置,添加环境变量

![设置vercel 环境变量](/img/img_12.png)

```
需要设置4个环境变量,1个是必填的

token: bot 机器人的token
sign_key: 加密 chat_id 需要用到,不设置默认为 abc
url: webhook 回调地址, 不设置的话请求 setWebhook 时需要手动加参数, webhook url 地址为:https://你的域名/webhook
key: 设置 webhook 的请求参数
```

![oSJRB.png](/img/img_12.png)

上面的环境变量设置好了之后,可能不会立马生效,你可以重新构建一下函数

![oSP9s.png](/img/img_13.png)

### 设置回调
设置 webhook ,可以直接通过浏览器请求来设置

webhook地址为:`https://你的域名/webhook`

浏览器窗口打开:`https://你的域名/setwebhook?key=环境变量设置的KEY&url=你的webhook地址`

`code` 返回 200 就是设置成功了~


================================================
FILE: api/Bot.php
================================================
<?php

/**
 * 简单封装 tg bot 请求
 * Class Bot
 * @author Alone88
 * @link https://alone88.cn
 */
class Bot
{
    // chat_id sign key
    private string $key;
    //Bot Token
    private string $token;

    public function __construct()
    {
        $this->token = $_ENV['token'];
        $this->key = $_ENV['sign_key'] ?? 'abc';
    }

    public function request($method, $data)
    {
        $curl = curl_init();

        curl_setopt_array($curl, array(
            CURLOPT_URL => sprintf('https://api.telegram.org/bot%s/%s', $this->token, $method),
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS => $data,
        ));
        $response = curl_exec($curl);
        curl_close($curl);
        return json_decode($response, true);
    }

    public function sendMessage($data): array
    {
        return $this->request('sendMessage', $data);
    }

    public function setWebHook($data)
    {
        return $this->request('setWebhook', $data);
    }

    public function encryption($chat_id): string
    {
        return base64_encode($this->key . $chat_id);
    }

    public function decryption($text): string
    {
        return substr(base64_decode($text), strlen($this->key));
    }

    /**
     * @param string $key
     * @return Bot
     */
    public function setKey(string $key): Bot
    {
        $this->key = $key;
        return $this;
    }

    /**
     * @param string $token
     * @return Bot
     */
    public function setToken(string $token): Bot
    {
        $this->token = $token;
        return $this;
    }
}

================================================
FILE: api/index.php
================================================
<?php
require_once 'Bot.php';

header('content-type: application/json');
$token = $_REQUEST['token'] ?? null;
$message = $_REQUEST['message'] ?? '';

$bot = new Bot();

if (is_null($token)) {
    echo json_encode(['code' => 422, 'message' => 'token 不能为空']);
} else {
    // 发送消息
    $chat_id = $bot->decryption($token);
    $ret = $bot->sendMessage(['text' => $message, 'chat_id' => $chat_id]);
    if ($ret['ok']) {
        echo json_encode(['code' => 200, 'message' => 'success']);
    } else {
        echo json_encode(['code' => 422, 'message' => $ret['description']]);
    }
}

================================================
FILE: api/setWebHook.php
================================================
<?php
header('content-type: application/json');

$key = $_REQUEST['key'] ?? '';

if ($key !== $_ENV['key']) {
    echo json_encode(['code' => 422, 'message' => '设置秘钥错误']);
} else {
    //开始设置回调url
    $url = $_REQUEST['url'] ?? $_ENV['url'];
    require_once 'Bot.php';
    $data = ['url' => $url];
    $bot = new Bot();
    $ret = $bot->setWebHook($data);
    if ($ret['ok']) {
        echo json_encode(['code' => 200, 'message' => '设置成功']);
    } else {
        echo json_encode(['code' => 422, 'message' => $ret['description']]);
    }
}

================================================
FILE: api/webhook.php
================================================
<?php
header('content-type: application/json');
require_once 'Bot.php';
$bot = new Bot();
// 获取/token 命令,获取聊天 id
$data = json_decode(file_get_contents("php://input"), true);
$message = $data['message']['text'] ?? '';
if ($message === '/token') {
    $chat_id = $data['message']['chat']['id'];
    $bot->sendMessage(['text' => $bot->encryption($chat_id), 'chat_id' => $chat_id]);
}
echo json_encode(['code' => 200, 'message' => 'success']);

================================================
FILE: edge_deploy/edge.html
================================================
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>TG 消息推送机器人 - 边缘函数版</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="keywords" content="TG,机器人,telegram,提醒,消息,通知,边缘函数,Edge Functions" />
    <meta name="description" content="一个由腾讯云边缘函数驱动的Telegram提醒机器人,server酱的telegram版,服务稳定,无依赖,可长期使用" />
    <style type="text/css">/*! normalize.css v3.0.1 | MIT License | git.io/normalize */

    /**
     * 1. Set default font family to sans-serif.
     * 2. Prevent iOS text size adjust after orientation change, without disabling
     *    user zoom.
     */

    html {
        font-family: sans-serif; /* 1 */
        -ms-text-size-adjust: 100%; /* 2 */
        -webkit-text-size-adjust: 100%; /* 2 */
    }

    /**
     * Remove default margin.
     */

    body {
        margin: 0;
    }

    /* HTML5 display definitions
       ========================================================================== */

    /**
     * Correct `block` display not defined for any HTML5 element in IE 8/9.
     * Correct `block` display not defined for `details` or `summary` in IE 10/11 and Firefox.
     * Correct `block` display not defined for `main` in IE 11.
     */

    article,
    aside,
    details,
    figcaption,
    figure,
    footer,
    header,
    hgroup,
    main,
    nav,
    section,
    summary {
        display: block;
    }

    /**
     * 1. Correct `inline-block` display not defined in IE 8/9.
     * 2. Normalize vertical alignment of `progress` in Chrome, Firefox, and Opera.
     */

    audio,
    canvas,
    progress,
    video {
        display: inline-block; /* 1 */
        vertical-align: baseline; /* 2 */
    }

    /**
     * Prevent modern browsers from displaying `audio` without controls.
     * Remove excess height in iOS 5 devices.
     */

    audio:not([controls]) {
        display: none;
        height: 0;
    }

    /**
     * Address `[hidden]` styling not present in IE 8/9/10.
     * Hide the `template` element in IE 8/9/11, Safari, and Firefox < 22.
     */

    [hidden],
    template {
        display: none;
    }

    /* Links
       ========================================================================== */

    /**
     * Remove the gray background color from active links in IE 10.
     */

    a {
        background: transparent;
    }

    /**
     * Improve readability when focused and also mouse hovered in all browsers.
     */

    a:active,
    a:hover {
        outline: 0;
    }

    /* Text-level semantics
       ========================================================================== */

    /**
     * Address styling not present in IE 8/9/10/11, Safari, and Chrome.
     */

    abbr[title] {
        border-bottom: 1px dotted;
    }

    /**
     * Address style set to `bolder` in Firefox 4+, Safari, and Chrome.
     */

    b,
    strong {
        font-weight: bold;
    }

    /**
     * Address styling not present in Safari and Chrome.
     */

    dfn {
        font-style: italic;
    }

    /**
     * Address variable `h1` font-size and margin within `section` and `article`
     * contexts in Firefox 4+, Safari, and Chrome.
     */

    h1 {
        font-size: 2em;
        margin: 0.67em 0;
    }

    /**
     * Address styling not present in IE 8/9.
     */

    mark {
        background: #ff0;
        color: #000;
    }

    /**
     * Address inconsistent and variable font size in all browsers.
     */

    small {
        font-size: 80%;
    }

    /**
     * Prevent `sub` and `sup` affecting `line-height` in all browsers.
     */

    sub,
    sup {
        font-size: 75%;
        line-height: 0;
        position: relative;
        vertical-align: baseline;
    }

    sup {
        top: -0.5em;
    }

    sub {
        bottom: -0.25em;
    }

    /* Embedded content
       ========================================================================== */

    /**
     * Remove border when inside `a` element in IE 8/9/10.
     */

    img {
        border: 0;
    }

    /**
     * Correct overflow not hidden in IE 9/10/11.
     */

    svg:not(:root) {
        overflow: hidden;
    }

    /* Grouping content
       ========================================================================== */

    /**
     * Address margin not present in IE 8/9 and Safari.
     */

    figure {
        margin: 1em 40px;
    }

    /**
     * Address differences between Firefox and other browsers.
     */

    hr {
        -moz-box-sizing: content-box;
        box-sizing: content-box;
        height: 0;
    }

    /**
     * Contain overflow in all browsers.
     */

    pre {
        overflow: auto;
    }

    /**
     * Address odd `em`-unit font size rendering in all browsers.
     */

    code,
    kbd,
    pre,
    samp {
        font-family: monospace, monospace;
        font-size: 1em;
    }

    /* Forms
       ========================================================================== */

    /**
     * Known limitation: by default, Chrome and Safari on OS X allow very limited
     * styling of `select`, unless a `border` property is set.
     */

    /**
     * 1. Correct color not being inherited.
     *    Known issue: affects color of disabled elements.
     * 2. Correct font properties not being inherited.
     * 3. Address margins set differently in Firefox 4+, Safari, and Chrome.
     */

    button,
    input,
    optgroup,
    select,
    textarea {
        color: inherit; /* 1 */
        font: inherit; /* 2 */
        margin: 0; /* 3 */
    }

    /**
     * Address `overflow` set to `hidden` in IE 8/9/10/11.
     */

    button {
        overflow: visible;
    }

    /**
     * Address inconsistent `text-transform` inheritance for `button` and `select`.
     * All other form control elements do not inherit `text-transform` values.
     * Correct `button` style inheritance in Firefox, IE 8/9/10/11, and Opera.
     * Correct `select` style inheritance in Firefox.
     */

    button,
    select {
        text-transform: none;
    }

    /**
     * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio`
     *    and `video` controls.
     * 2. Correct inability to style clickable `input` types in iOS.
     * 3. Improve usability and consistency of cursor style between image-type
     *    `input` and others.
     */

    button,
    html input[type="button"], /* 1 */
    input[type="reset"],
    input[type="submit"] {
        -webkit-appearance: button; /* 2 */
        cursor: pointer; /* 3 */
    }

    /**
     * Re-set default cursor for disabled elements.
     */

    button[disabled],
    html input[disabled] {
        cursor: default;
    }

    /**
     * Remove inner padding and border in Firefox 4+.
     */

    button::-moz-focus-inner,
    input::-moz-focus-inner {
        border: 0;
        padding: 0;
    }

    /**
     * Address Firefox 4+ setting `line-height` on `input` using `!important` in
     * the UA stylesheet.
     */

    input {
        line-height: normal;
    }

    /**
     * It's recommended that you don't attempt to style these elements.
     * Firefox's implementation doesn't respect box-sizing, padding, or width.
     *
     * 1. Address box sizing set to `content-box` in IE 8/9/10.
     * 2. Remove excess padding in IE 8/9/10.
     */

    input[type="checkbox"],
    input[type="radio"] {
        box-sizing: border-box; /* 1 */
        padding: 0; /* 2 */
    }

    /**
     * Fix the cursor style for Chrome's increment/decrement buttons. For certain
     * `font-size` values of the `input`, it causes the cursor style of the
     * decrement button to change from `default` to `text`.
     */

    input[type="number"]::-webkit-inner-spin-button,
    input[type="number"]::-webkit-outer-spin-button {
        height: auto;
    }

    /**
     * 1. Address `appearance` set to `searchfield` in Safari and Chrome.
     * 2. Address `box-sizing` set to `border-box` in Safari and Chrome
     *    (include `-moz` to future-proof).
     */

    input[type="search"] {
        -webkit-appearance: textfield; /* 1 */
        -moz-box-sizing: content-box;
        -webkit-box-sizing: content-box; /* 2 */
        box-sizing: content-box;
    }

    /**
     * Remove inner padding and search cancel button in Safari and Chrome on OS X.
     * Safari (but not Chrome) clips the cancel button when the search input has
     * padding (and `textfield` appearance).
     */

    input[type="search"]::-webkit-search-cancel-button,
    input[type="search"]::-webkit-search-decoration {
        -webkit-appearance: none;
    }

    /**
     * Define consistent border, margin, and padding.
     */

    fieldset {
        border: 1px solid #c0c0c0;
        margin: 0 2px;
        padding: 0.35em 0.625em 0.75em;
    }

    /**
     * 1. Correct `color` not being inherited in IE 8/9/10/11.
     * 2. Remove padding so people aren't caught out if they zero out fieldsets.
     */

    legend {
        border: 0; /* 1 */
        padding: 0; /* 2 */
    }

    /**
     * Remove default vertical scrollbar in IE 8/9/10/11.
     */

    textarea {
        overflow: auto;
    }

    /**
     * Don't inherit the `font-weight` (applied by a rule above).
     * NOTE: the default cannot safely be changed in Chrome and Safari on OS X.
     */

    optgroup {
        font-weight: bold;
    }

    /* Tables
       ========================================================================== */

    /**
     * Remove most spacing between table cells.
     */

    table {
        border-collapse: collapse;
        border-spacing: 0;
    }

    td,
    th {
        padding: 0;
    }

    /* mscore */
    * {
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
    }

    *:before,
    *:after {
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
    }

    html {
        font-size: 62.5%;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    }

    body {
        /*font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;*/
        font-family: 'Helvetica Neue', Helvetica, Arial, 'Microsoft Yahei', sans-serif;
        font-size: 14px;
        line-height: 1.42857143;
        color: #333333;
        background-color: #ffffff;
    }

    input,
    button,
    select,
    textarea {
        font-family: inherit;
        font-size: inherit;
        line-height: inherit;
    }

    a {
        color: #428bca;
        text-decoration: none;
    }

    a:hover,
    a:focus {
        color: #2a6496;
        text-decoration: underline;
    }

    a:focus {
        outline: thin dotted;
        outline: 5px auto -webkit-focus-ring-color;
        outline-offset: -2px;
    }

    figure {
        margin: 0;
    }

    img {
        vertical-align: middle;
    }

    /*
    Original style from softwaremaniacs.org (c) Ivan Sagalaev <Maniac@SoftwareManiacs.Org>
    */

    .hljs {
        display: block;
        overflow-x: auto;
        padding: 0.5em;
        background: #f0f0f0;
        -webkit-text-size-adjust: none;
    }

    .hljs,
    .hljs-subst,
    .hljs-tag .hljs-title,
    .nginx .hljs-title {
        color: black;
    }

    .hljs-string,
    .hljs-title,
    .hljs-constant,
    .hljs-parent,
    .hljs-tag .hljs-value,
    .hljs-rules .hljs-value,
    .hljs-preprocessor,
    .hljs-pragma,
    .haml .hljs-symbol,
    .ruby .hljs-symbol,
    .ruby .hljs-symbol .hljs-string,
    .hljs-template_tag,
    .django .hljs-variable,
    .smalltalk .hljs-class,
    .hljs-addition,
    .hljs-flow,
    .hljs-stream,
    .bash .hljs-variable,
    .apache .hljs-tag,
    .apache .hljs-cbracket,
    .tex .hljs-command,
    .tex .hljs-special,
    .erlang_repl .hljs-function_or_atom,
    .asciidoc .hljs-header,
    .markdown .hljs-header,
    .coffeescript .hljs-attribute {
        color: #800;
    }

    .smartquote,
    .hljs-comment,
    .hljs-annotation,
    .diff .hljs-header,
    .hljs-chunk,
    .asciidoc .hljs-blockquote,
    .markdown .hljs-blockquote {
        color: #888;
    }

    .hljs-number,
    .hljs-date,
    .hljs-regexp,
    .hljs-literal,
    .hljs-hexcolor,
    .smalltalk .hljs-symbol,
    .smalltalk .hljs-char,
    .go .hljs-constant,
    .hljs-change,
    .lasso .hljs-variable,
    .makefile .hljs-variable,
    .asciidoc .hljs-bullet,
    .markdown .hljs-bullet,
    .asciidoc .hljs-link_url,
    .markdown .hljs-link_url {
        color: #080;
    }

    .hljs-label,
    .hljs-javadoc,
    .ruby .hljs-string,
    .hljs-decorator,
    .hljs-filter .hljs-argument,
    .hljs-localvars,
    .hljs-array,
    .hljs-attr_selector,
    .hljs-important,
    .hljs-pseudo,
    .hljs-pi,
    .haml .hljs-bullet,
    .hljs-doctype,
    .hljs-deletion,
    .hljs-envvar,
    .hljs-shebang,
    .apache .hljs-sqbracket,
    .nginx .hljs-built_in,
    .tex .hljs-formula,
    .erlang_repl .hljs-reserved,
    .hljs-prompt,
    .asciidoc .hljs-link_label,
    .markdown .hljs-link_label,
    .vhdl .hljs-attribute,
    .clojure .hljs-attribute,
    .asciidoc .hljs-attribute,
    .lasso .hljs-attribute,
    .coffeescript .hljs-property,
    .hljs-phony {
        color: #88f;
    }

    .hljs-keyword,
    .hljs-id,
    .hljs-title,
    .hljs-built_in,
    .css .hljs-tag,
    .hljs-javadoctag,
    .hljs-phpdoc,
    .hljs-dartdoc,
    .hljs-yardoctag,
    .smalltalk .hljs-class,
    .hljs-winutils,
    .bash .hljs-variable,
    .apache .hljs-tag,
    .hljs-type,
    .hljs-typename,
    .tex .hljs-command,
    .asciidoc .hljs-strong,
    .markdown .hljs-strong,
    .hljs-request,
    .hljs-status {
        font-weight: bold;
    }

    .asciidoc .hljs-emphasis,
    .markdown .hljs-emphasis {
        font-style: italic;
    }

    .nginx .hljs-built_in {
        font-weight: normal;
    }

    .coffeescript .javascript,
    .javascript .xml,
    .lasso .markup,
    .tex .hljs-formula,
    .xml .javascript,
    .xml .vbscript,
    .xml .css,
    .xml .hljs-cdata {
        opacity: 0.5;
    }

    #container {
        padding: 15px;
        margin-left: 20px;
    }

    pre {
        border: 1px solid #ccc;
        border-radius: 4px;
        display: block;
    }

    pre code {
        white-space: pre-wrap;
    }

    .hljs,
    code {
        font-family: Monaco, Menlo, Consolas, 'Courier New', monospace;
    }

    pre {
        background-color: #dddddd;
        padding: 8px 0px 8px 30px;
        word-wrap: break-word;
    }

    table tbody tr:nth-child(2n) {
        background: rgba(158, 188, 226, 0.12);
    }

    :not(pre) > code {
        padding: 2px 4px;
        font-size: 90%;
        color: #c7254e;
        background-color: #f9f2f4;
        white-space: nowrap;
        border-radius: 4px;
    }

    th, td {
        border: 1px solid #ccc;
        padding: 6px 12px;
    }

    blockquote {
        border-left-width: 10px;
        background-color: rgba(102, 128, 153, 0.05);
        border-top-right-radius: 5px;
        border-bottom-right-radius: 5px;
        padding: 1px 20px
    }

    blockquote.pull-right small:before, blockquote.pull-right .small:before {
        content: ''
    }

    blockquote.pull-right small:after, blockquote.pull-right .small:after {
        content: '\00A0 \2014'
    }

    blockquote:before, blockquote:after {
        content: ""
    }

    blockquote {
        margin: 0 0 1.1em
    }

    blockquote p {
        margin-bottom: 1.1em;
        font-size: 1em;
        line-height: 1.45
    }

    blockquote ul:last-child, blockquote ol:last-child {
        margin-bottom: 0
    }

    blockquote {
        margin: 0 0 21px;
        border-left: 10px solid #dddddd;
    }</style>
    <style type="text/css" abt="234"></style>
    <input type="hidden" id="_w_elixir"></head>
<body marginwidth="0" marginheight="0">
<div id="container">
    <h2 id="-">接口名称</h2>
    <h3 id="1-">1) 边缘函数地址</h3>
    <blockquote>
        <p>你的边缘函数触发地址, 例如: <code>https://your-domain.com/</code></p>
    </blockquote>
    <h3 id="2-http-get-post">2) 调用方式:HTTP GET / POST</h3>
    <h3 id="3-">3) 接口描述:</h3>
    <ul>
        <li>TG版消息推送机器人, 由 <strong>腾讯云 Page Functions</strong> 强力驱动.</li>
        <li>关注机器人 <a href="https://t.me/msg_sause_bot">MessageBot</a> (或你自己的Bot).</li>
        <li>向机器人发送 <code>/token</code> 获取你的专属 Token.</li>
        <li>你需要在腾讯云控制台为你的边缘函数配置三个环境变量: <code>token</code>, <code>sign_key</code>, <code>key</code>.</li>
    </ul>
    <h3 id="4-">4) 请求 API:</h3>

    <h4>/sendMessage (发送消息)</h4>
    <table>
        <thead>
        <tr>
            <th>字段名称</th>
            <th style="text-align:center">类型</th>
            <th style="text-align:center">必填</th>
            <th style="text-align:right">备注</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td>token</td>
            <td style="text-align:center">string</td>
            <td style="text-align:center">Y</td>
            <td style="text-align:right">从机器人获取的 Token</td>
        </tr>
        <tr>
            <td>message</td>
            <td style="text-align:center">string</td>
            <td style="text-align:center">Y</td>
            <td style="text-align:right">要发送的消息内容</td>
        </tr>
        </tbody>
    </table>
    <p>请求示例:</p>
    <pre><code>GET /sendMessage?token=YOUR_TOKEN&message=Hello+World
</code></pre>

    <h4>/setWebhook (设置回调)</h4>
    <table>
        <thead>
        <tr>
            <th>字段名称</th>
            <th style="text-align:center">类型</th>
            <th style="text-align:center">必填</th>
            <th style="text-align:right">备注</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td>key</td>
            <td style="text-align:center">string</td>
            <td style="text-align:center">Y</td>
            <td style="text-align:right">你在环境变量中设置的 <code>key</code></td>
        </tr>
        <tr>
            <td>url</td>
            <td style="text-align:center">string</td>
            <td style-="text-align:center">N</td>
            <td style="text-align:right">可选, 自定义 webhook 地址, 默认为当前函数地址 + <code>/webhook</code></td>
        </tr>
        </tbody>
    </table>
    <p>请求示例:</p>
    <pre><code>GET /setWebhook?key=YOUR_ADMIN_KEY
</code></pre>

    <h4>/webhook (接收回调)</h4>
    <p>此接口用于接收来自 Telegram 的 POST 请求,通常无需手动调用。</p>


    <h3 id="5-">5) 请求返回结果:</h3>
    <pre><code>{"code":200,"message":"success"}
</code></pre>
</div>
</body>
</html> 

================================================
FILE: edgeone.json
================================================
{
    "name": "TGMessage",
    "outputDirectory": "./edge_deploy"
  }

================================================
FILE: functions/bot.js
================================================
class Bot {
    // chat_id sign key
    key;
    //Bot Token
    token;

    constructor(env) {
        this.token = env.token;
        this.key = env.sign_key ?? 'abc';
    }

    async request(method, data) {
        const url = `https://api.telegram.org/bot${this.token}/${method}`;
        const response = await fetch(url, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(data)
        });
        return await response.json();
    }

    async sendMessage(data) {
        return this.request('sendMessage', data);
    }

    async setWebHook(data) {
        return this.request('setWebhook', data);
    }

    encryption(chat_id) {
        const text = this.key + chat_id;
        return Buffer.from(text).toString('base64');
    }

    decryption(text) {
        const decoded = Buffer.from(text, 'base64').toString('ascii');
        return decoded.substring(this.key.length);
    }
}

export default Bot; 

================================================
FILE: functions/sendMessage.js
================================================
import Bot from './bot.js';

export async function onRequest(context) {
    const { request, env } = context;
    const bot = new Bot(env);

    let token, message;

    if (request.method === 'POST') {
        const contentType = request.headers.get('content-type') || '';
        if (contentType.includes('application/json')) {
            const body = await request.json();
            token = body.token;
            message = body.message;
        } else if (contentType.includes('application/x-www-form-urlencoded') || contentType.includes('multipart/form-data')) {
            const formData = await request.formData();
            token = formData.get('token');
            message = formData.get('message');
        }
    } else { // GET request
        const url = new URL(request.url);
        token = url.searchParams.get('token');
        message = url.searchParams.get('message');
    }

    if (!token) {
        return new Response(JSON.stringify({ code: 422, message: 'token 不能为空' }), {
            headers: { 'Content-Type': 'application/json' },
            status: 422
        });
    }

    try {
        const chat_id = bot.decryption(token);
        const ret = await bot.sendMessage({ text: message, chat_id: chat_id });

        if (ret.ok) {
            return new Response(JSON.stringify({ code: 200, message: 'success' }), {
                headers: { 'Content-Type': 'application/json' },
                status: 200
            });
        } else {
            return new Response(JSON.stringify({ code: 422, message: ret.description }), {
                headers: { 'Content-Type': 'application/json' },
                status: 422
            });
        }
    } catch (e) {
        return new Response(JSON.stringify({ code: 500, message: 'Token decryption failed or other server error.' }), {
            headers: { 'Content-Type': 'application/json' },
            status: 500
        });
    }
} 

================================================
FILE: functions/setWebhook.js
================================================
import Bot from './bot.js';

export async function onRequest(context) {
    const { request, env } = context;
    const bot = new Bot(env);
    const url = new URL(request.url);

    const key = url.searchParams.get('key');

    if (key !== env.key) {
        return new Response(JSON.stringify({ code: 401, message: 'unauthorized' }), {
            headers: { 'Content-Type': 'application/json' },
            status: 401
        });
    }

    // Default webhook URL is the current function's host + /webhook
    const webhookUrl = url.searchParams.get('url') || `https://${url.hostname}/webhook`;
    
    const ret = await bot.setWebHook({ url: webhookUrl });

    if (ret.ok) {
        return new Response(JSON.stringify({ code: 200, message: `Webhook set to ${webhookUrl}` }), {
            headers: { 'Content-Type': 'application/json' }
        });
    } else {
        return new Response(JSON.stringify({ code: 422, message: ret.description }), {
            headers: { 'Content-Type': 'application/json' },
            status: 422
        });
    }
} 

================================================
FILE: functions/webhook.js
================================================
import Bot from './bot.js';

export async function onRequest(context) {
    const { request, env } = context;
    const bot = new Bot(env);

    if (request.method !== 'POST') {
        return new Response('Please use POST method', { status: 405 });
    }

    try {
        const data = await request.json();
        const message = data.message?.text ?? '';

        if (message === '/token') {
            const chat_id = data.message.chat.id;
            await bot.sendMessage({ text: bot.encryption(chat_id), chat_id: chat_id });
        }
    } catch (e) {
        // Log the error but still return a success response to Telegram
        // to avoid repeated webhook calls.
        console.error(e);
    }
    
    // Always return a success response to Telegram
    return new Response(JSON.stringify({ code: 200, message: 'success' }), {
        headers: { 'Content-Type': 'application/json' }
    });
} 

================================================
FILE: index.html
================================================
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>TG 消息推送机器人</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="keywords" content="TG,机器人,telegram,提醒,消息,通知,server酱," />
    <meta name="description" content="一个telegram提醒机器人,server酱的telegram版,搭建在vercel,服务稳定,无依赖,可长期使用" />
    <style type="text/css">/*! normalize.css v3.0.1 | MIT License | git.io/normalize */

    /**
     * 1. Set default font family to sans-serif.
     * 2. Prevent iOS text size adjust after orientation change, without disabling
     *    user zoom.
     */

    html {
        font-family: sans-serif; /* 1 */
        -ms-text-size-adjust: 100%; /* 2 */
        -webkit-text-size-adjust: 100%; /* 2 */
    }

    /**
     * Remove default margin.
     */

    body {
        margin: 0;
    }

    /* HTML5 display definitions
       ========================================================================== */

    /**
     * Correct `block` display not defined for any HTML5 element in IE 8/9.
     * Correct `block` display not defined for `details` or `summary` in IE 10/11 and Firefox.
     * Correct `block` display not defined for `main` in IE 11.
     */

    article,
    aside,
    details,
    figcaption,
    figure,
    footer,
    header,
    hgroup,
    main,
    nav,
    section,
    summary {
        display: block;
    }

    /**
     * 1. Correct `inline-block` display not defined in IE 8/9.
     * 2. Normalize vertical alignment of `progress` in Chrome, Firefox, and Opera.
     */

    audio,
    canvas,
    progress,
    video {
        display: inline-block; /* 1 */
        vertical-align: baseline; /* 2 */
    }

    /**
     * Prevent modern browsers from displaying `audio` without controls.
     * Remove excess height in iOS 5 devices.
     */

    audio:not([controls]) {
        display: none;
        height: 0;
    }

    /**
     * Address `[hidden]` styling not present in IE 8/9/10.
     * Hide the `template` element in IE 8/9/11, Safari, and Firefox < 22.
     */

    [hidden],
    template {
        display: none;
    }

    /* Links
       ========================================================================== */

    /**
     * Remove the gray background color from active links in IE 10.
     */

    a {
        background: transparent;
    }

    /**
     * Improve readability when focused and also mouse hovered in all browsers.
     */

    a:active,
    a:hover {
        outline: 0;
    }

    /* Text-level semantics
       ========================================================================== */

    /**
     * Address styling not present in IE 8/9/10/11, Safari, and Chrome.
     */

    abbr[title] {
        border-bottom: 1px dotted;
    }

    /**
     * Address style set to `bolder` in Firefox 4+, Safari, and Chrome.
     */

    b,
    strong {
        font-weight: bold;
    }

    /**
     * Address styling not present in Safari and Chrome.
     */

    dfn {
        font-style: italic;
    }

    /**
     * Address variable `h1` font-size and margin within `section` and `article`
     * contexts in Firefox 4+, Safari, and Chrome.
     */

    h1 {
        font-size: 2em;
        margin: 0.67em 0;
    }

    /**
     * Address styling not present in IE 8/9.
     */

    mark {
        background: #ff0;
        color: #000;
    }

    /**
     * Address inconsistent and variable font size in all browsers.
     */

    small {
        font-size: 80%;
    }

    /**
     * Prevent `sub` and `sup` affecting `line-height` in all browsers.
     */

    sub,
    sup {
        font-size: 75%;
        line-height: 0;
        position: relative;
        vertical-align: baseline;
    }

    sup {
        top: -0.5em;
    }

    sub {
        bottom: -0.25em;
    }

    /* Embedded content
       ========================================================================== */

    /**
     * Remove border when inside `a` element in IE 8/9/10.
     */

    img {
        border: 0;
    }

    /**
     * Correct overflow not hidden in IE 9/10/11.
     */

    svg:not(:root) {
        overflow: hidden;
    }

    /* Grouping content
       ========================================================================== */

    /**
     * Address margin not present in IE 8/9 and Safari.
     */

    figure {
        margin: 1em 40px;
    }

    /**
     * Address differences between Firefox and other browsers.
     */

    hr {
        -moz-box-sizing: content-box;
        box-sizing: content-box;
        height: 0;
    }

    /**
     * Contain overflow in all browsers.
     */

    pre {
        overflow: auto;
    }

    /**
     * Address odd `em`-unit font size rendering in all browsers.
     */

    code,
    kbd,
    pre,
    samp {
        font-family: monospace, monospace;
        font-size: 1em;
    }

    /* Forms
       ========================================================================== */

    /**
     * Known limitation: by default, Chrome and Safari on OS X allow very limited
     * styling of `select`, unless a `border` property is set.
     */

    /**
     * 1. Correct color not being inherited.
     *    Known issue: affects color of disabled elements.
     * 2. Correct font properties not being inherited.
     * 3. Address margins set differently in Firefox 4+, Safari, and Chrome.
     */

    button,
    input,
    optgroup,
    select,
    textarea {
        color: inherit; /* 1 */
        font: inherit; /* 2 */
        margin: 0; /* 3 */
    }

    /**
     * Address `overflow` set to `hidden` in IE 8/9/10/11.
     */

    button {
        overflow: visible;
    }

    /**
     * Address inconsistent `text-transform` inheritance for `button` and `select`.
     * All other form control elements do not inherit `text-transform` values.
     * Correct `button` style inheritance in Firefox, IE 8/9/10/11, and Opera.
     * Correct `select` style inheritance in Firefox.
     */

    button,
    select {
        text-transform: none;
    }

    /**
     * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio`
     *    and `video` controls.
     * 2. Correct inability to style clickable `input` types in iOS.
     * 3. Improve usability and consistency of cursor style between image-type
     *    `input` and others.
     */

    button,
    html input[type="button"], /* 1 */
    input[type="reset"],
    input[type="submit"] {
        -webkit-appearance: button; /* 2 */
        cursor: pointer; /* 3 */
    }

    /**
     * Re-set default cursor for disabled elements.
     */

    button[disabled],
    html input[disabled] {
        cursor: default;
    }

    /**
     * Remove inner padding and border in Firefox 4+.
     */

    button::-moz-focus-inner,
    input::-moz-focus-inner {
        border: 0;
        padding: 0;
    }

    /**
     * Address Firefox 4+ setting `line-height` on `input` using `!important` in
     * the UA stylesheet.
     */

    input {
        line-height: normal;
    }

    /**
     * It's recommended that you don't attempt to style these elements.
     * Firefox's implementation doesn't respect box-sizing, padding, or width.
     *
     * 1. Address box sizing set to `content-box` in IE 8/9/10.
     * 2. Remove excess padding in IE 8/9/10.
     */

    input[type="checkbox"],
    input[type="radio"] {
        box-sizing: border-box; /* 1 */
        padding: 0; /* 2 */
    }

    /**
     * Fix the cursor style for Chrome's increment/decrement buttons. For certain
     * `font-size` values of the `input`, it causes the cursor style of the
     * decrement button to change from `default` to `text`.
     */

    input[type="number"]::-webkit-inner-spin-button,
    input[type="number"]::-webkit-outer-spin-button {
        height: auto;
    }

    /**
     * 1. Address `appearance` set to `searchfield` in Safari and Chrome.
     * 2. Address `box-sizing` set to `border-box` in Safari and Chrome
     *    (include `-moz` to future-proof).
     */

    input[type="search"] {
        -webkit-appearance: textfield; /* 1 */
        -moz-box-sizing: content-box;
        -webkit-box-sizing: content-box; /* 2 */
        box-sizing: content-box;
    }

    /**
     * Remove inner padding and search cancel button in Safari and Chrome on OS X.
     * Safari (but not Chrome) clips the cancel button when the search input has
     * padding (and `textfield` appearance).
     */

    input[type="search"]::-webkit-search-cancel-button,
    input[type="search"]::-webkit-search-decoration {
        -webkit-appearance: none;
    }

    /**
     * Define consistent border, margin, and padding.
     */

    fieldset {
        border: 1px solid #c0c0c0;
        margin: 0 2px;
        padding: 0.35em 0.625em 0.75em;
    }

    /**
     * 1. Correct `color` not being inherited in IE 8/9/10/11.
     * 2. Remove padding so people aren't caught out if they zero out fieldsets.
     */

    legend {
        border: 0; /* 1 */
        padding: 0; /* 2 */
    }

    /**
     * Remove default vertical scrollbar in IE 8/9/10/11.
     */

    textarea {
        overflow: auto;
    }

    /**
     * Don't inherit the `font-weight` (applied by a rule above).
     * NOTE: the default cannot safely be changed in Chrome and Safari on OS X.
     */

    optgroup {
        font-weight: bold;
    }

    /* Tables
       ========================================================================== */

    /**
     * Remove most spacing between table cells.
     */

    table {
        border-collapse: collapse;
        border-spacing: 0;
    }

    td,
    th {
        padding: 0;
    }

    /* mscore */
    * {
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
    }

    *:before,
    *:after {
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
    }

    html {
        font-size: 62.5%;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    }

    body {
        /*font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;*/
        font-family: 'Helvetica Neue', Helvetica, Arial, 'Microsoft Yahei', sans-serif;
        font-size: 14px;
        line-height: 1.42857143;
        color: #333333;
        background-color: #ffffff;
    }

    input,
    button,
    select,
    textarea {
        font-family: inherit;
        font-size: inherit;
        line-height: inherit;
    }

    a {
        color: #428bca;
        text-decoration: none;
    }

    a:hover,
    a:focus {
        color: #2a6496;
        text-decoration: underline;
    }

    a:focus {
        outline: thin dotted;
        outline: 5px auto -webkit-focus-ring-color;
        outline-offset: -2px;
    }

    figure {
        margin: 0;
    }

    img {
        vertical-align: middle;
    }

    /*
    Original style from softwaremaniacs.org (c) Ivan Sagalaev <Maniac@SoftwareManiacs.Org>
    */

    .hljs {
        display: block;
        overflow-x: auto;
        padding: 0.5em;
        background: #f0f0f0;
        -webkit-text-size-adjust: none;
    }

    .hljs,
    .hljs-subst,
    .hljs-tag .hljs-title,
    .nginx .hljs-title {
        color: black;
    }

    .hljs-string,
    .hljs-title,
    .hljs-constant,
    .hljs-parent,
    .hljs-tag .hljs-value,
    .hljs-rules .hljs-value,
    .hljs-preprocessor,
    .hljs-pragma,
    .haml .hljs-symbol,
    .ruby .hljs-symbol,
    .ruby .hljs-symbol .hljs-string,
    .hljs-template_tag,
    .django .hljs-variable,
    .smalltalk .hljs-class,
    .hljs-addition,
    .hljs-flow,
    .hljs-stream,
    .bash .hljs-variable,
    .apache .hljs-tag,
    .apache .hljs-cbracket,
    .tex .hljs-command,
    .tex .hljs-special,
    .erlang_repl .hljs-function_or_atom,
    .asciidoc .hljs-header,
    .markdown .hljs-header,
    .coffeescript .hljs-attribute {
        color: #800;
    }

    .smartquote,
    .hljs-comment,
    .hljs-annotation,
    .diff .hljs-header,
    .hljs-chunk,
    .asciidoc .hljs-blockquote,
    .markdown .hljs-blockquote {
        color: #888;
    }

    .hljs-number,
    .hljs-date,
    .hljs-regexp,
    .hljs-literal,
    .hljs-hexcolor,
    .smalltalk .hljs-symbol,
    .smalltalk .hljs-char,
    .go .hljs-constant,
    .hljs-change,
    .lasso .hljs-variable,
    .makefile .hljs-variable,
    .asciidoc .hljs-bullet,
    .markdown .hljs-bullet,
    .asciidoc .hljs-link_url,
    .markdown .hljs-link_url {
        color: #080;
    }

    .hljs-label,
    .hljs-javadoc,
    .ruby .hljs-string,
    .hljs-decorator,
    .hljs-filter .hljs-argument,
    .hljs-localvars,
    .hljs-array,
    .hljs-attr_selector,
    .hljs-important,
    .hljs-pseudo,
    .hljs-pi,
    .haml .hljs-bullet,
    .hljs-doctype,
    .hljs-deletion,
    .hljs-envvar,
    .hljs-shebang,
    .apache .hljs-sqbracket,
    .nginx .hljs-built_in,
    .tex .hljs-formula,
    .erlang_repl .hljs-reserved,
    .hljs-prompt,
    .asciidoc .hljs-link_label,
    .markdown .hljs-link_label,
    .vhdl .hljs-attribute,
    .clojure .hljs-attribute,
    .asciidoc .hljs-attribute,
    .lasso .hljs-attribute,
    .coffeescript .hljs-property,
    .hljs-phony {
        color: #88f;
    }

    .hljs-keyword,
    .hljs-id,
    .hljs-title,
    .hljs-built_in,
    .css .hljs-tag,
    .hljs-javadoctag,
    .hljs-phpdoc,
    .hljs-dartdoc,
    .hljs-yardoctag,
    .smalltalk .hljs-class,
    .hljs-winutils,
    .bash .hljs-variable,
    .apache .hljs-tag,
    .hljs-type,
    .hljs-typename,
    .tex .hljs-command,
    .asciidoc .hljs-strong,
    .markdown .hljs-strong,
    .hljs-request,
    .hljs-status {
        font-weight: bold;
    }

    .asciidoc .hljs-emphasis,
    .markdown .hljs-emphasis {
        font-style: italic;
    }

    .nginx .hljs-built_in {
        font-weight: normal;
    }

    .coffeescript .javascript,
    .javascript .xml,
    .lasso .markup,
    .tex .hljs-formula,
    .xml .javascript,
    .xml .vbscript,
    .xml .css,
    .xml .hljs-cdata {
        opacity: 0.5;
    }

    #container {
        padding: 15px;
        margin-left: 20px;
    }

    pre {
        border: 1px solid #ccc;
        border-radius: 4px;
        display: block;
    }

    pre code {
        white-space: pre-wrap;
    }

    .hljs,
    code {
        font-family: Monaco, Menlo, Consolas, 'Courier New', monospace;
    }

    pre {
        background-color: #dddddd;
        padding: 8px 0px 8px 30px;
        word-wrap: break-word;
    }

    table tbody tr:nth-child(2n) {
        background: rgba(158, 188, 226, 0.12);
    }

    :not(pre) > code {
        padding: 2px 4px;
        font-size: 90%;
        color: #c7254e;
        background-color: #f9f2f4;
        white-space: nowrap;
        border-radius: 4px;
    }

    th, td {
        border: 1px solid #ccc;
        padding: 6px 12px;
    }

    blockquote {
        border-left-width: 10px;
        background-color: rgba(102, 128, 153, 0.05);
        border-top-right-radius: 5px;
        border-bottom-right-radius: 5px;
        padding: 1px 20px
    }

    blockquote.pull-right small:before, blockquote.pull-right .small:before {
        content: ''
    }

    blockquote.pull-right small:after, blockquote.pull-right .small:after {
        content: '\00A0 \2014'
    }

    blockquote:before, blockquote:after {
        content: ""
    }

    blockquote {
        margin: 0 0 1.1em
    }

    blockquote p {
        margin-bottom: 1.1em;
        font-size: 1em;
        line-height: 1.45
    }

    blockquote ul:last-child, blockquote ol:last-child {
        margin-bottom: 0
    }

    blockquote {
        margin: 0 0 21px;
        border-left: 10px solid #dddddd;
    }</style>
    <style type="text/css" abt="234"></style>
    <input type="hidden" id="_w_elixir"></head>
<body marginwidth="0" marginheight="0">
<div id="container"><h2 id="-">接口名称</h2>
    <h3 id="1-">1) 请求地址</h3>
    <blockquote>
        <p><a href="https://tg-message.vercel.app/api">https://tg-message.vercel.app/api</a>
        </p>
    </blockquote>
    <h3 id="2-http-get">2) 调用方式:HTTP get post</h3>
    <h3 id="3-">3) 接口描述:</h3>
    <ul>
        <li>TG版消息推送机器人,基于 vercel 函数搭建,免服务器</li>
        <li>关注机器人 <a href="https://t.me/msg_sause_bot">MessageBot</a></li>
        <li>发送 <code>/token</code> 获取 token </li>
        <li>Github: <a href="https://github.com/anhao/TgMessage">https://github.com/anhao/TgMessage</a></li>
        <li><a href="https://vercel.com/new/git/external?repository-url=https%3A%2F%2Fgithub.com%2Fanhao%2FTGMessage"><img src="https://vercel.com/button" alt=""></a></li>
    </ul>
    <h3 id="4-">4) 请求参数:</h3>
    <table>
        <thead>
        <tr>
            <th>字段名称</th>
            <th style="text-align:center">字段说明</th>
            <th style="text-align:center">类型</th>
            <th style="text-align:center">必填</th>
            <th style="text-align:right">备注</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td>token</td>
            <td style="text-align:center"></td>
            <td style="text-align:center">string</td>
            <td style="text-align:center">Y</td>
            <td style="text-align:right">token</td>
        </tr>
        <tr>
            <td>message</td>
            <td style="text-align:center"></td>
            <td style="text-align:center">string</td>
            <td style="text-align:center">Y</td>
            <td style="text-align:right">要发送的消息内容</td>
        </tr>
        </tbody>
    </table>
    <h3 id="5-">5) 请求返回结果:</h3>
    <pre><code>{"code":200,"message":"success"}
</code></pre>
</div>
</body>
</html>

================================================
FILE: vercel.json
================================================
{
  "functions": {
    "api/*.php": {
      "runtime": "vercel-php@0.5.2"
    }
  },
  "routes": [
    {
      "src": "/setWebHook",
      "dest": "/api/setWebHook.php"
    },
    {
      "src": "/webhook",
      "dest": "/api/webhook.php"
    }
  ]
}
Download .txt
gitextract_com7y8vo/

├── .edgeone/
│   └── project.json
├── .gitignore
├── LICENSE
├── README.md
├── api/
│   ├── Bot.php
│   ├── index.php
│   ├── setWebHook.php
│   └── webhook.php
├── edge_deploy/
│   └── edge.html
├── edgeone.json
├── functions/
│   ├── bot.js
│   ├── sendMessage.js
│   ├── setWebhook.js
│   └── webhook.js
├── index.html
└── vercel.json
Download .txt
SYMBOL INDEX (19 symbols across 5 files)

FILE: api/Bot.php
  class Bot (line 9) | class Bot
    method __construct (line 16) | public function __construct()
    method request (line 22) | public function request($method, $data)
    method sendMessage (line 42) | public function sendMessage($data): array
    method setWebHook (line 47) | public function setWebHook($data)
    method encryption (line 52) | public function encryption($chat_id): string
    method decryption (line 57) | public function decryption($text): string
    method setKey (line 66) | public function setKey(string $key): Bot
    method setToken (line 76) | public function setToken(string $token): Bot

FILE: functions/bot.js
  class Bot (line 1) | class Bot {
    method constructor (line 7) | constructor(env) {
    method request (line 12) | async request(method, data) {
    method sendMessage (line 24) | async sendMessage(data) {
    method setWebHook (line 28) | async setWebHook(data) {
    method encryption (line 32) | encryption(chat_id) {
    method decryption (line 37) | decryption(text) {

FILE: functions/sendMessage.js
  function onRequest (line 3) | async function onRequest(context) {

FILE: functions/setWebhook.js
  function onRequest (line 3) | async function onRequest(context) {

FILE: functions/webhook.js
  function onRequest (line 3) | async function onRequest(context) {
Condensed preview — 16 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (68K chars).
[
  {
    "path": ".edgeone/project.json",
    "chars": 63,
    "preview": "{\n  \"Name\": \"tg-message\",\n  \"ProjectId\": \"pages-ywhm4l7gjx2i\"\n}"
  },
  {
    "path": ".gitignore",
    "chars": 98,
    "preview": ".vercel\n.idea\n.idea/\n# Tencent Cloud EdgeOne\n.env\n.edgeone/*\n!.edgeone/project.json\n.tef_dist/*\n  "
  },
  {
    "path": "LICENSE",
    "chars": 11348,
    "preview": "                        Apache License\n                           Version 2.0, January 2004\n                        http"
  },
  {
    "path": "README.md",
    "chars": 5243,
    "preview": "[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https%3A%2F%2Fgith"
  },
  {
    "path": "api/Bot.php",
    "chars": 1818,
    "preview": "<?php\n\n/**\n * 简单封装 tg bot 请求\n * Class Bot\n * @author Alone88\n * @link https://alone88.cn\n */\nclass Bot\n{\n    // chat_id "
  },
  {
    "path": "api/index.php",
    "chars": 581,
    "preview": "<?php\nrequire_once 'Bot.php';\n\nheader('content-type: application/json');\n$token = $_REQUEST['token'] ?? null;\n$message ="
  },
  {
    "path": "api/setWebHook.php",
    "chars": 540,
    "preview": "<?php\nheader('content-type: application/json');\n\n$key = $_REQUEST['key'] ?? '';\n\nif ($key !== $_ENV['key']) {\n    echo j"
  },
  {
    "path": "api/webhook.php",
    "chars": 439,
    "preview": "<?php\nheader('content-type: application/json');\nrequire_once 'Bot.php';\n$bot = new Bot();\n// 获取/token 命令,获取聊天 id\n$data ="
  },
  {
    "path": "edge_deploy/edge.html",
    "chars": 18502,
    "preview": "<!doctype html>\n<html>\n<head>\n    <meta charset=\"utf-8\">\n    <title>TG 消息推送机器人 - 边缘函数版</title>\n    <meta http-equiv=\"X-U"
  },
  {
    "path": "edgeone.json",
    "chars": 69,
    "preview": "{\n    \"name\": \"TGMessage\",\n    \"outputDirectory\": \"./edge_deploy\"\n  }"
  },
  {
    "path": "functions/bot.js",
    "chars": 1016,
    "preview": "class Bot {\n    // chat_id sign key\n    key;\n    //Bot Token\n    token;\n\n    constructor(env) {\n        this.token = env"
  },
  {
    "path": "functions/sendMessage.js",
    "chars": 1932,
    "preview": "import Bot from './bot.js';\n\nexport async function onRequest(context) {\n    const { request, env } = context;\n    const "
  },
  {
    "path": "functions/setWebhook.js",
    "chars": 1062,
    "preview": "import Bot from './bot.js';\n\nexport async function onRequest(context) {\n    const { request, env } = context;\n    const "
  },
  {
    "path": "functions/webhook.js",
    "chars": 912,
    "preview": "import Bot from './bot.js';\n\nexport async function onRequest(context) {\n    const { request, env } = context;\n    const "
  },
  {
    "path": "index.html",
    "chars": 17665,
    "preview": "<!doctype html>\n<html>\n<head>\n    <meta charset=\"utf-8\">\n    <title>TG 消息推送机器人</title>\n    <meta http-equiv=\"X-UA-Compat"
  },
  {
    "path": "vercel.json",
    "chars": 252,
    "preview": "{\n  \"functions\": {\n    \"api/*.php\": {\n      \"runtime\": \"vercel-php@0.5.2\"\n    }\n  },\n  \"routes\": [\n    {\n      \"src\": \"/"
  }
]

About this extraction

This page contains the full source code of the anhao/TgMessage GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 16 files (60.1 KB), approximately 17.2k tokens, and a symbol index with 19 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!