Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: send telegram form request bug #279

Merged
merged 8 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,5 @@ out
/config.json
/wrangler.toml
/wrangler-test.toml
/plugins/interpolate.js
/dist/index.cjs
/dist/index.d.ts
2 changes: 1 addition & 1 deletion dist/buildinfo.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/timestamp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion doc/cn/PLATFORM.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

### 2. [Vercel](https://vercel.com/)

详情看[Vercel](VERCEL)。免费,无需域名,无需服务器。需要配置本地开发环境部署,不能通过复制粘贴部署。无存储服务,需要自己配置数据库。可以使用[Redis Cloud](https://redis.com)的免费redis。可以连接github自动部署,但是需要了解vercel的配置。
详情看[Vercel](VERCEL.md)。免费,无需域名,无需服务器。需要配置本地开发环境部署,不能通过复制粘贴部署。无存储服务,需要自己配置数据库。可以使用[Redis Cloud](https://redis.com)的免费redis。可以连接github自动部署,但是需要了解vercel的配置。


### 3. Local
Expand Down
8 changes: 8 additions & 0 deletions doc/cn/VERCEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

`/src/adapter/vercel`中提供了示例代码,可以完成Vercel部署,和基础的功能测试。但是无法保证所有功能都能正常工作。

### 自动部署

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FTBXark%2FChatGPT-Telegram-Workers&env=UPSTASH_REDIS_REST_URL,UPSTASH_REDIS_REST_TOKEN,VERCEL_DOMAIN,TELEGRAM_AVAILABLE_TOKENS&project-name=chatgpt-telegram-workers&repository-name=ChatGPT-Telegram-Workers&demo-title=ChatGPT-Telegram-Workers&demo-description=Deploy%20your%20own%20Telegram%20ChatGPT%20bot%20on%20Cloudflare%20Workers%20with%20ease.&demo-url=https%3A%2F%2Fchatgpt-telegram-workers.vercel.app)


### 手动部署

```shell
yarn global add vercel # 安装vercel命令行工具
yarn # 安装依赖
Expand All @@ -11,4 +18,5 @@ yarn run deploy:vercel # 部署到vercel
```

### 已知问题

1. redis 连接关闭有问题会导致客户端连接数过多导致无法连接建议使用upstash的redis服务
2 changes: 1 addition & 1 deletion doc/en/PLATFORM.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The easiest way, the deployment method supported by this project by default, see

### 2. [Vercel](https://vercel.com/)

See details at [Vercel](../cn/VERCEL). It is free, does not require a domain name or server. Deployment requires configuring the local development environment and cannot be done by copying and pasting. There is no storage service, so you need to configure your own database. You can use the free Redis from [Redis Cloud](https://redis.com). It can connect to GitHub for automatic deployment, but you need to understand Vercel's configuration.
See details at [Vercel](VERCEL.md). It is free, does not require a domain name or server. Deployment requires configuring the local development environment and cannot be done by copying and pasting. There is no storage service, so you need to configure your own database. You can use the free Redis from [Redis Cloud](https://redis.com). It can connect to GitHub for automatic deployment, but you need to understand Vercel's configuration.

### 3. Local

Expand Down
9 changes: 9 additions & 0 deletions doc/en/VERCEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

The `/src/adapter/vercel` provides sample code that can complete Vercel deployment and basic functional testing. However, it cannot guarantee that all functions will work properly.


### Automatic deployment

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FTBXark%2FChatGPT-Telegram-Workers&env=UPSTASH_REDIS_REST_URL,UPSTASH_REDIS_REST_TOKEN,VERCEL_DOMAIN,TELEGRAM_AVAILABLE_TOKENS&project-name=chatgpt-telegram-workers&repository-name=ChatGPT-Telegram-Workers&demo-title=ChatGPT-Telegram-Workers&demo-description=Deploy%20your%20own%20Telegram%20ChatGPT%20bot%20on%20Cloudflare%20Workers%20with%20ease.&demo-url=https%3A%2F%2Fchatgpt-telegram-workers.vercel.app)


### Manual deployment

```shell
yarn global add vercel # Install the Vercel command-line tool.
yarn # Install dependencies.
Expand All @@ -11,4 +19,5 @@ yarn run deploy:vercel # Deploy to Vercel.
```

### Known issue.

1. There is a problem with closing Redis connections, which can cause too many client connections and make it impossible to connect. It is recommended to use Upstash's Redis service.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "chatgpt-telegram-workers",
"type": "module",
"version": "1.9.2",
"version": "1.9.3",
"description": "The easiest and quickest way to deploy your own ChatGPT Telegram bot is to use a single file and simply copy and paste it. There is no need for any dependencies, local development environment configuration, domain names, or servers.",
"author": "TBXark",
"license": "MIT",
Expand All @@ -28,6 +28,7 @@
"deploy:dist": "wrangler deploy",
"deploy:build": "npm run build && wrangler deploy",
"deploy:vercel": "vercel deploy --prod",
"deploy:plugin": "BUILD_MODE=plugins-page vite build && wrangler pages deploy plugins --project-name=interpolate-test --branch=main",
"start:dist": "node dist/index.js",
"start:local": "CONFIG_PATH=./config.json TOML_PATH=./wrangler.toml tsx src/adapter/local/index.ts",
"start:debug": "wrangler dev --local",
Expand All @@ -46,7 +47,7 @@
"eslint-plugin-format": "^0.1.2",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-node-externals": "^7.1.3",
"telegram-bot-api-types": "^7.9.10",
"telegram-bot-api-types": "^7.9.12",
"tsx": "^4.19.0",
"typescript": "^5.5.4",
"vite": "^5.4.2",
Expand Down
1 change: 1 addition & 0 deletions plugins/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dist
2 changes: 1 addition & 1 deletion plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ For example, define the following variables in the environment variables:

```toml
PLUGIN_COMMAND_dns = "https://raw.githubusercontent.com/TBXark/ChatGPT-Telegram-Workers/dev/plugins/dns.json"
PLUGIN_COMMAND_DESCRIPTION_dns = "DNS query /dns <type> <domain>"
PLUGIN_DESCRIPTION_dns = "DNS query /dns <type> <domain>"
```

Then enter `/dns A www.baidu.com` in the command line to call the plugin.
Expand Down
2 changes: 1 addition & 1 deletion plugins/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export interface RequestTemplate {

```toml
PLUGIN_COMMAND_dns = "https://raw.githubusercontent.com/TBXark/ChatGPT-Telegram-Workers/dev/plugins/dns.json"
PLUGIN_COMMAND_DESCRIPTION_dns = "DNS查询 /dns <类型> <域名>"
PLUGIN_DESCRIPTION_dns = "DNS查询 /dns <类型> <域名>"
```

然后在命令行中输入`/dns A www.baidu.com`即可调用插件
Expand Down
4 changes: 2 additions & 2 deletions plugins/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ChatGPT-Telegram-Workers</title>
<script type="module" src="interpolate.js"></script>
<script type="module" src="dist/interpolate.js"></script>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
Expand Down Expand Up @@ -133,7 +133,7 @@ <h2>preview</h2>

<script type="module">

import { interpolate } from './interpolate.js';
import { interpolate } from './dist/interpolate.js';

function updatePreview() {
const template = document.getElementById('template').value;
Expand Down
1 change: 0 additions & 1 deletion src/adapter/vercel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ENV } from '../../config/env';
import { createRouter } from '../../route';

export default async function (request: VercelRequest, response: VercelResponse) {
const redis: UpStashRedis | null = null;
try {
const {
UPSTASH_REDIS_REST_URL,
Expand Down
2 changes: 1 addition & 1 deletion src/telegram/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class APIClientBase {
formData.append(key, JSON.stringify(value));
}
}
return fetch(`${this.baseURL}bot${this.token}/${method}`, {
return fetch(`${this.baseURL}/bot${this.token}/${method}`, {
method: 'POST',
body: formData,
});
Expand Down
1 change: 1 addition & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"buildCommand": "npm run build:vercel",
"builds": [
{ "src": "dist/**", "use": "@vercel/node" }
],
Expand Down
10 changes: 9 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ const plugins: Plugin[] = [
];

let entry: string;
let outDir = 'dist';
let fileName = 'index';
let formats: LibraryFormats[] = ['es'];
switch (BUILD_MODE) {
case 'plugins-page':
entry = 'src/plugins/interpolate.ts';
fileName = 'interpolate';
outDir = 'plugins/dist';
break;
case 'local':
entry = 'src/adapter/local/index.ts';
plugins.push(createDockerPlugin('dist'));
Expand All @@ -53,10 +60,11 @@ export default defineConfig({
target: 'esnext',
lib: {
entry: path.resolve(__dirname, entry),
fileName: 'index',
fileName,
formats,
},
minify: false,
outDir,
},
define: {
...versionDefine,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4699,10 +4699,10 @@ tar@^6.0.2, tar@^6.1.11, tar@^6.1.2:
mkdirp "^1.0.3"
yallist "^4.0.0"

telegram-bot-api-types@^7.9.10:
version "7.9.10"
resolved "https://registry.yarnpkg.com/telegram-bot-api-types/-/telegram-bot-api-types-7.9.10.tgz#e519fa8ffec912cf0567025b83364d7905f74c2a"
integrity sha512-T8wwAxclKu5vT1HWKeHiLuotWN2WxBM3gM75zCUAZcEWMXuIuFBU15zq39jkgk6wz179UYKitvCMNsxgyfCE+w==
telegram-bot-api-types@^7.9.12:
version "7.9.12"
resolved "https://registry.yarnpkg.com/telegram-bot-api-types/-/telegram-bot-api-types-7.9.12.tgz#0631d9e87d5190c21283415150f7b5f16af33cec"
integrity sha512-RM69ix6NdgTIxPFjqI5qO5AEGsMsc623AvsJPWjYHMvcTV9Zvx3/VBYCyTpMoVUSYy8NmQ9zQx0xUJVGAe14Dg==

text-table@^0.2.0:
version "0.2.0"
Expand Down
Loading