@alemonjs/telegram 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +142 -0
- package/package.json +35 -0
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# [https://lemonade-lab.github.io/alemonjs.com/](https://lemonade-lab.github.io/alemonjs.com/)
|
|
2
|
+
|
|
3
|
+
跨平台开发的事件驱动机器人
|
|
4
|
+
|
|
5
|
+
## USE
|
|
6
|
+
|
|
7
|
+
- telegram
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
yarn add @alemonjs/telegram
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
- alemon.config.yaml
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
telegram:
|
|
17
|
+
# 令牌
|
|
18
|
+
token: ''
|
|
19
|
+
# 主人
|
|
20
|
+
master_id: null
|
|
21
|
+
# 前缀(非必填)
|
|
22
|
+
intent: null
|
|
23
|
+
# 活动 非必填)
|
|
24
|
+
shard: null
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Community
|
|
28
|
+
|
|
29
|
+
QQ Group 806943302
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { defineBot, Text, OnProcessor, useParse } from 'alemonjs';
|
|
2
|
+
import Client from 'node-telegram-bot-api';
|
|
3
|
+
|
|
4
|
+
var index = defineBot(config => {
|
|
5
|
+
//
|
|
6
|
+
const client = new Client(config.token, {
|
|
7
|
+
polling: true,
|
|
8
|
+
baseApiUrl: '',
|
|
9
|
+
request: {
|
|
10
|
+
url: '',
|
|
11
|
+
proxy: 'http://127.0.0.1:7890'
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
// channel_post 消息
|
|
15
|
+
client.on('channel_post', event => {
|
|
16
|
+
// 定义消
|
|
17
|
+
const e = {
|
|
18
|
+
// 事件类型
|
|
19
|
+
Platform: 'telegram',
|
|
20
|
+
// 频道
|
|
21
|
+
GuildId: String(event.chat.id),
|
|
22
|
+
// 子频道
|
|
23
|
+
ChannelId: String(event.chat.id),
|
|
24
|
+
// 是否是主人
|
|
25
|
+
IsMaster: false,
|
|
26
|
+
// 用户ID
|
|
27
|
+
UserId: String(event?.sender_chat?.id),
|
|
28
|
+
// 用户名
|
|
29
|
+
UserName: event.sender_chat.username,
|
|
30
|
+
// 用户头像
|
|
31
|
+
UserAvatar: '',
|
|
32
|
+
// 格式化数据
|
|
33
|
+
MsgId: String(event.message_id),
|
|
34
|
+
// 用户消息
|
|
35
|
+
Megs: [Text(event.text ?? '')],
|
|
36
|
+
// 用户openId
|
|
37
|
+
OpenID: 'test',
|
|
38
|
+
// 创建时间
|
|
39
|
+
CreateAt: Date.now(),
|
|
40
|
+
//
|
|
41
|
+
value: null
|
|
42
|
+
};
|
|
43
|
+
// 当访问的时候获取
|
|
44
|
+
Object.defineProperty(e, 'value', {
|
|
45
|
+
get() {
|
|
46
|
+
return event;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
// 处理消息
|
|
50
|
+
OnProcessor(e, 'message.create');
|
|
51
|
+
});
|
|
52
|
+
// const eventKeys: string[] = [
|
|
53
|
+
// 'message',
|
|
54
|
+
// 'text',
|
|
55
|
+
// 'animation',
|
|
56
|
+
// 'audio',
|
|
57
|
+
// 'channel_chat_created',
|
|
58
|
+
// 'contact',
|
|
59
|
+
// 'delete_chat_photo',
|
|
60
|
+
// 'document',
|
|
61
|
+
// 'game',
|
|
62
|
+
// 'group_chat_created',
|
|
63
|
+
// 'invoice',
|
|
64
|
+
// 'left_chat_member',
|
|
65
|
+
// 'location',
|
|
66
|
+
// 'migrate_from_chat_id',
|
|
67
|
+
// 'migrate_to_chat_id',
|
|
68
|
+
// 'new_chat_members',
|
|
69
|
+
// 'new_chat_photo',
|
|
70
|
+
// 'new_chat_title',
|
|
71
|
+
// 'passport_data',
|
|
72
|
+
// 'photo',
|
|
73
|
+
// 'pinned_message',
|
|
74
|
+
// 'sticker',
|
|
75
|
+
// 'successful_payment',
|
|
76
|
+
// 'supergroup_chat_created',
|
|
77
|
+
// 'video',
|
|
78
|
+
// 'video_note',
|
|
79
|
+
// 'voice',
|
|
80
|
+
// 'video_chat_started',
|
|
81
|
+
// 'video_chat_ended',
|
|
82
|
+
// 'video_chat_participants_invited',
|
|
83
|
+
// 'video_chat_scheduled',
|
|
84
|
+
// 'message_auto_delete_timer_changed',
|
|
85
|
+
// 'chat_invite_link',
|
|
86
|
+
// 'chat_member_updated',
|
|
87
|
+
// 'web_app_data',
|
|
88
|
+
// 'callback_query',
|
|
89
|
+
// 'inline_query',
|
|
90
|
+
// 'poll',
|
|
91
|
+
// 'poll_answer',
|
|
92
|
+
// 'chat_member',
|
|
93
|
+
// 'my_chat_member',
|
|
94
|
+
// 'chosen_inline_result',
|
|
95
|
+
// // hannel
|
|
96
|
+
// 'channel_post',
|
|
97
|
+
// // edited
|
|
98
|
+
// 'edited_message',
|
|
99
|
+
// 'edited_message_text',
|
|
100
|
+
// 'edited_message_caption',
|
|
101
|
+
// // 频道消息修改
|
|
102
|
+
// 'edited_channel_post',
|
|
103
|
+
// // 频道消息修改
|
|
104
|
+
// 'edited_channel_post_text',
|
|
105
|
+
// // 频道消息修改
|
|
106
|
+
// 'edited_channel_post_caption',
|
|
107
|
+
// 'shipping_query',
|
|
108
|
+
// 'pre_checkout_query',
|
|
109
|
+
// 'polling_error',
|
|
110
|
+
// 'webhook_error',
|
|
111
|
+
// 'chat_join_request'
|
|
112
|
+
// ]
|
|
113
|
+
// 打印全部的消息
|
|
114
|
+
// for (const key of eventKeys) {
|
|
115
|
+
// client.on(key, event => {
|
|
116
|
+
// console.log(key, event)
|
|
117
|
+
// })
|
|
118
|
+
// }
|
|
119
|
+
return {
|
|
120
|
+
api: {
|
|
121
|
+
use: {
|
|
122
|
+
send: (event, val) => {
|
|
123
|
+
if (val.length < 0)
|
|
124
|
+
return Promise.all([]);
|
|
125
|
+
if (val.length < 0)
|
|
126
|
+
return Promise.all([]);
|
|
127
|
+
const content = useParse(val, 'Text');
|
|
128
|
+
if (content) {
|
|
129
|
+
return Promise.all([content].map(item => client.sendMessage(event.GuildId, item)));
|
|
130
|
+
}
|
|
131
|
+
const images = useParse(val, 'Image');
|
|
132
|
+
if (images) {
|
|
133
|
+
return Promise.all(images.map(item => client.sendPhoto(event.GuildId, item)));
|
|
134
|
+
}
|
|
135
|
+
return Promise.all([]);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
export { index as default };
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alemonjs/telegram",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "telegram-bot",
|
|
5
|
+
"author": "ningmengchongshui",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "lib/index.js",
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"chat-space": "^0.0.4",
|
|
11
|
+
"grammy": "^1.30.0",
|
|
12
|
+
"node-telegram-bot-api": "^0.66.0"
|
|
13
|
+
},
|
|
14
|
+
"types": "lib",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": "./lib/index.js",
|
|
18
|
+
"types": "./lib/index.d.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public",
|
|
23
|
+
"registry": "https://registry.npmjs.org"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"alemonjs",
|
|
27
|
+
"telegram",
|
|
28
|
+
"telegram-bot",
|
|
29
|
+
"bot",
|
|
30
|
+
"chat-bot"
|
|
31
|
+
],
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node-telegram-bot-api": "^0.64.7"
|
|
34
|
+
}
|
|
35
|
+
}
|