@alemonjs/telegram 0.0.5 → 0.1.0
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/lib/index.d.ts +5 -1
- package/lib/index.js +20 -8
- package/package.json +3 -3
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import TelegramClient from 'node-telegram-bot-api';
|
|
2
|
+
|
|
3
|
+
type Client = typeof TelegramClient.prototype;
|
|
4
|
+
declare const client: Client;
|
|
1
5
|
declare const _default: () => typeof global.alemonjs;
|
|
2
6
|
|
|
3
|
-
export { _default as default };
|
|
7
|
+
export { type Client, client, _default as default };
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { defineBot, getConfig, Text, OnProcessor, useParse } from 'alemonjs';
|
|
2
|
-
import
|
|
2
|
+
import TelegramClient from 'node-telegram-bot-api';
|
|
3
3
|
|
|
4
|
+
const client = global.client;
|
|
4
5
|
var index = defineBot(() => {
|
|
5
6
|
//
|
|
6
7
|
const cfg = getConfig();
|
|
@@ -8,7 +9,7 @@ var index = defineBot(() => {
|
|
|
8
9
|
if (!config)
|
|
9
10
|
return;
|
|
10
11
|
//
|
|
11
|
-
const client = new
|
|
12
|
+
const client = new TelegramClient(config.token, {
|
|
12
13
|
polling: true,
|
|
13
14
|
baseApiUrl: config?.base_api_url ?? '',
|
|
14
15
|
request: {
|
|
@@ -79,7 +80,7 @@ var index = defineBot(() => {
|
|
|
79
80
|
// 格式化数据
|
|
80
81
|
MsgId: String(event?.message_id),
|
|
81
82
|
// 用户消息
|
|
82
|
-
|
|
83
|
+
MessageBody: [Text(event?.text)],
|
|
83
84
|
// 用户openId
|
|
84
85
|
OpenID: String(event?.chat?.id),
|
|
85
86
|
// 创建时间
|
|
@@ -110,12 +111,16 @@ var index = defineBot(() => {
|
|
|
110
111
|
UserId: String(event?.from.id),
|
|
111
112
|
// 用户名
|
|
112
113
|
UserName: event?.from?.username,
|
|
114
|
+
GuildIdName: '',
|
|
115
|
+
GuildIdAvatar: '',
|
|
116
|
+
ChannelName: '',
|
|
113
117
|
// 用户头像
|
|
114
118
|
UserAvatar: UserAvatar,
|
|
115
119
|
// 格式化数据
|
|
116
120
|
MsgId: String(event?.message_id),
|
|
117
121
|
// 用户消息
|
|
118
|
-
|
|
122
|
+
MessageBody: [Text(event?.text)],
|
|
123
|
+
MessageText: event?.text,
|
|
119
124
|
// 用户openId
|
|
120
125
|
OpenID: String(event?.chat?.id),
|
|
121
126
|
// 创建时间
|
|
@@ -166,7 +171,9 @@ var index = defineBot(() => {
|
|
|
166
171
|
// 格式化数据
|
|
167
172
|
MsgId: String(event?.message_id),
|
|
168
173
|
// 用户消息
|
|
169
|
-
|
|
174
|
+
MessageBody: [Text(event?.text)],
|
|
175
|
+
//
|
|
176
|
+
MessageText: event?.text,
|
|
170
177
|
// 用户openId
|
|
171
178
|
OpenID: String(event?.chat?.id),
|
|
172
179
|
// 创建时间
|
|
@@ -252,6 +259,7 @@ var index = defineBot(() => {
|
|
|
252
259
|
// console.log(key, event)
|
|
253
260
|
// })
|
|
254
261
|
// }
|
|
262
|
+
global.client = client;
|
|
255
263
|
return {
|
|
256
264
|
api: {
|
|
257
265
|
use: {
|
|
@@ -260,12 +268,16 @@ var index = defineBot(() => {
|
|
|
260
268
|
return Promise.all([]);
|
|
261
269
|
if (val.length < 0)
|
|
262
270
|
return Promise.all([]);
|
|
263
|
-
const content = useParse(
|
|
271
|
+
const content = useParse({
|
|
272
|
+
MessageBody: val
|
|
273
|
+
}, 'Text');
|
|
264
274
|
const e = event?.value;
|
|
265
275
|
if (content) {
|
|
266
276
|
return Promise.all([content].map(item => client.sendMessage(e.chat.id, item)));
|
|
267
277
|
}
|
|
268
|
-
const images = useParse(
|
|
278
|
+
const images = useParse({
|
|
279
|
+
MessageBody: val
|
|
280
|
+
}, 'Image');
|
|
269
281
|
if (images) {
|
|
270
282
|
return Promise.all(images.map(item => client.sendPhoto(e.chat.id, item)));
|
|
271
283
|
}
|
|
@@ -276,4 +288,4 @@ var index = defineBot(() => {
|
|
|
276
288
|
};
|
|
277
289
|
});
|
|
278
290
|
|
|
279
|
-
export { index as default };
|
|
291
|
+
export { client, index as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alemonjs/telegram",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "telegram-bot",
|
|
5
5
|
"author": "lemonade",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"registry": "https://registry.npmjs.org",
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
|
-
"bugs": "https://github.com/
|
|
34
|
+
"bugs": "https://github.com/lemonade-lab/alemonjs/issues",
|
|
35
35
|
"repository": {
|
|
36
36
|
"type": "git",
|
|
37
|
-
"url": "https://github.com/
|
|
37
|
+
"url": "https://github.com/lemonade-lab/alemonjs.git"
|
|
38
38
|
}
|
|
39
39
|
}
|