Skip to content

Commit ea0b30c

Browse files
committed
add old webhook
1 parent 3e5dfbb commit ea0b30c

File tree

8 files changed

+198
-198
lines changed

8 files changed

+198
-198
lines changed

.env-sample

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# <YOUR_BOT_TOKEN>
2+
BOT_TOKEN=""
3+
# <Random_string_to_make_chat_id_safe>
4+
TCKEY=""
5+
VERCEL_URL=""
6+
PORT=""
7+
# development
8+
NODE_ENV=""
9+
DEBUG=bot*,lib*

.prettierrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"singleQuote": true,
33
"trailingComma": "all",
44
"arrowParens": "avoid",
5-
"printWidth": 120,
5+
"printWidth": 80,
66
"useTabs": true
77
}

README.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
⚠️⚠️⚠️ 由于近期 vercel 环境疑似做了调整,新部署的机器人识别命令会报错(原来创建的机器人不受影响),我最近没空修改此项目,先 Archive 掉。着急使用的同学可以 fork & fix 先。
22

3-
# TeleChan - message api for telegram bot
4-
> 可供多人发送消息的 telegram 机器人 api , 类似server酱的开源实现
3+
# TeleChan - message api for telegram bot
4+
5+
> 可供多人发送消息的 telegram 机器人 api , 类似 server 酱的开源实现
56
67
## 🎈 本项目属于方糖推送生态。该生态包含项目如下:
78

8-
- [Server酱Turbo](https://sct.ftqq.com):支持企业微信、微信服务号、钉钉、飞书群机器人等多通道的在线服务,无需搭建直接使用,每天有免费额度
9-
- [Wecom酱](https://github.com/easychen/wecomchan):通过企业微信推送消息到微信的消息推送函数和在线服务方案,开源免费,可自己搭建。支持多语言
10-
- [Tele酱](https://github.com/easychen/telechan):可以通过 Vercel 免费部署,且部署后 API 在国内网络可访问的 Telegram 多账户消息推送机器人
9+
- [Server 酱 Turbo](https://sct.ftqq.com):支持企业微信、微信服务号、钉钉、飞书群机器人等多通道的在线服务,无需搭建直接使用,每天有免费额度
10+
- [Wecom 酱](https://github.com/easychen/wecomchan):通过企业微信推送消息到微信的消息推送函数和在线服务方案,开源免费,可自己搭建。支持多语言
11+
- [Tele 酱](https://github.com/easychen/telechan):可以通过 Vercel 免费部署,且部署后 API 在国内网络可访问的 Telegram 多账户消息推送机器人
1112

1213
## 直接试用我搭建的机器人
1314

@@ -19,20 +20,20 @@
1920

2021
1. add @TeleChan8Bot in telegram
2122
2. `/sendkey` to get key & url
22-
3. send request via url
23+
3. send request via url
2324

2425
## How to use
2526

2627
1. star and fork this repo
2728
2. goto https://vercel.com/ create a new project, select the repo just created
28-
3. add [BotFather](https://t.me/botfather) in telegram, create new bot and get `telegram api token`
29-
4. set output dir to `dist` , set `BOT_TOKEN` to `telegram api token`, set `TCKEY` a random string ![image](https://user-images.githubusercontent.com/1294760/115171377-7c6ecd00-a0f5-11eb-8677-86f207ceb724.png)
29+
3. add [BotFather](https://t.me/botfather) in telegram, create new bot and get `telegram api token`
30+
4. set `BOT_TOKEN` to `telegram api token`, set `TCKEY` a random string ![image](https://user-images.githubusercontent.com/1294760/115171377-7c6ecd00-a0f5-11eb-8677-86f207ceb724.png)
3031
5. deploy
3132
6. send /sendkey command to the bot, you will get sendkey and api url
3233

3334
## API
3435

35-
Both HTTP `GET` or `POST` are OK
36+
Both HTTP `GET` or `POST` are OK
3637

3738
- sendkey,required
3839
- text,required
@@ -41,7 +42,7 @@ Both HTTP `GET` or `POST` are OK
4142

4243
`text` and `desp` support [telegram markdown](https://core.telegram.org/bots/api#markdownv2-style) which is a very small subset of markdown without image support
4344

44-
### send function
45+
### send function
4546

4647
```php
4748
function tg_send( $text , $desp = '' , $key = '<sendkey>' )
@@ -52,23 +53,22 @@ function tg_send( $text , $desp = '' , $key = '<sendkey>' )
5253
'method' => 'POST',
5354
'header' => 'Content-type: application/x-www-form-urlencoded',
5455
'content' => $postdata));
55-
56+
5657
$context = stream_context_create($opts);
5758
return $result = file_get_contents('telechan8.vercel.app/api/send?sendkey='.$key, false, $context);
58-
59+
5960
}
6061
```
6162

6263
## Thanks
6364

6465
Heavily modified base [Telegram Bot Boilerplate with Vercel's Serverless Functions](https://github.com/waptik/telegram-bot-boilerplate-now-serverless-api)
6566

66-
6767
## 中文教程
6868

6969
[![image](https://user-images.githubusercontent.com/1294760/115172022-f05da500-a0f6-11eb-9bb8-5919442523c6.png)](https://www.bilibili.com/video/BV1S5411c7Vy/)
7070

71-
[安装视频@B,欢迎关注作者](https://www.bilibili.com/video/BV1S5411c7Vy/)
71+
[安装视频@B,欢迎关注作者](https://www.bilibili.com/video/BV1S5411c7Vy/)
7272

7373
参数说明:
7474

@@ -79,7 +79,7 @@ Heavily modified base [Telegram Bot Boilerplate with Vercel's Serverless Functio
7979

8080
仅支持部分 Markdown 语法,任何不兼容以下语法的的提交,都会导致 400 错误。[注意不支持图片](https://core.telegram.org/bots/api#markdownv2-style),注意不支持图片,注意不支持图片:
8181

82-
```
82+
````
8383
*bold \*text*
8484
_italic \*text_
8585
__underline__
@@ -94,4 +94,4 @@ Heavily modified base [Telegram Bot Boilerplate with Vercel's Serverless Functio
9494
```python
9595
pre-formatted fixed-width code block written in the Python programming language
9696
```
97-
```
97+
````

api/index.ts

+18-20
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
// // import { NowRequest, NowResponse } from "@vercel/node";
2-
// import { VercelRequest, VercelResponse } from "@vercel/node";
1+
import { VercelRequest, VercelResponse } from '@vercel/node';
32

4-
// import { useWebhook } from "../src/lib";
5-
6-
// // main function
7-
// export default async function handle(req: VercelRequest, res: VercelResponse) {
8-
// try {
9-
// await useWebhook(req, res);
10-
// } catch (e) {
11-
// res.statusCode = 500;
12-
// res.json(e.message);
13-
// }
14-
// }
15-
16-
import { VercelRequest, VercelResponse } from "@vercel/node";
17-
import { startVercel } from "../src";
3+
import { useWebhook } from '../src/lib/telegram';
184

5+
// main function
196
export default async function handle(req: VercelRequest, res: VercelResponse) {
207
try {
21-
await startVercel(req, res);
8+
await useWebhook(req, res);
229
} catch (e: any) {
2310
res.statusCode = 500;
24-
res.setHeader("Content-Type", "text/html");
25-
res.end("<h1>Server Error</h1><p>Sorry, there was a problem</p>");
26-
console.error(e.message);
11+
res.json(e.message);
2712
}
2813
}
14+
15+
// import { startVercel } from '../src';
16+
17+
// export default async function handle(req: VercelRequest, res: VercelResponse) {
18+
// try {
19+
// // await startVercel(req, res);
20+
// } catch (e: any) {
21+
// res.statusCode = 500;
22+
// res.setHeader('Content-Type', 'text/html');
23+
// res.end('<h1>Server Error</h1><p>Sorry, there was a problem</p>');
24+
// console.error(e.message);
25+
// }
26+
// }

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
"name": "telechan-message-send-bot-alterby-virola",
33
"version": "2.0.1",
44
"description": "功能简单的TG机器人",
5-
"main": "src/index.ts",
5+
"main": "api/index.ts",
66
"author": "EasyChen",
77
"homepage": "https://twitter.com/easychen",
88
"scripts": {
9-
"dev": "DEBUG=bot* dotenv -- nodemon -e ts -x ts-node src/index.ts",
10-
"devWindows": "@powershell -Command $env:DEBUG='bot*';dotenv -- nodemon -e ts -x ts-node src/index.ts",
11-
"build": "ncc build src/index.ts -o public -m",
9+
"dev": "DEBUG=bot* dotenv -- nodemon -e ts -x ts-node src/lib/telegram.ts",
10+
"devWindows": "@powershell -Command $env:DEBUG='bot*';dotenv -- nodemon -e ts -x ts-node src/lib/telegram.ts",
11+
"build": "ncc build src/lib/telegram.ts -o public -m",
1212
"prettier": "prettier --single-quote --trailing-comma all --write 'src/**/*.ts'"
1313
},
1414
"dependencies": {

src/commands/about.ts

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const about = () => async (ctx: Context) => {
99
debug(`Triggered "about" command with message \n${message}`);
1010

1111
await ctx.replyWithMarkdownV2(message, { parse_mode: 'Markdown' });
12-
// return ctx.replyWithMarkdown(message);
1312
};
1413

1514
export { about };

src/index.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import { Telegraf } from "telegraf";
1+
import { Telegraf } from 'telegraf';
22

3-
import { about, sendkey } from "./commands";
4-
import { greeting } from "./text";
5-
import { VercelRequest, VercelResponse } from "@vercel/node";
6-
import { development, production } from "./core";
3+
import { about, sendkey } from './commands';
4+
import { greeting } from './text';
5+
import { VercelRequest, VercelResponse } from '@vercel/node';
6+
import { development, production } from './core';
77

8-
const BOT_TOKEN = process.env.BOT_TOKEN || "";
9-
const ENVIRONMENT = process.env.NODE_ENV || "";
8+
const BOT_TOKEN = process.env.BOT_TOKEN || '';
9+
const ENVIRONMENT = process.env.NODE_ENV || '';
1010

1111
const bot = new Telegraf(BOT_TOKEN);
1212

13-
bot.command("about", about()).command("sendkey", sendkey());
14-
bot.on("message", greeting());
13+
bot.command('about', about()).command('sendkey', sendkey());
14+
bot.on('message', greeting());
1515

1616
//prod mode (Vercel)
1717
export const startVercel = async (req: VercelRequest, res: VercelResponse) => {
1818
await production(req, res, bot);
1919
};
2020
//dev mode
21-
ENVIRONMENT !== "production" && development(bot);
21+
ENVIRONMENT !== 'production' && development(bot);

0 commit comments

Comments
 (0)