teledzik 1.1.3 → 1.2.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/context.js +111 -0
- package/lib/core/helpers/rich-sanitizer.js +2 -9
- package/lib/core/types/bot-api-recent.js +6 -0
- package/lib/core/types/rich-message.js +14 -1
- package/lib/core/types/typegram.js +1 -0
- package/lib/future.js +5 -0
- package/lib/index.js +2 -1
- package/lib/telegram.js +167 -0
- package/package.json +2 -2
- package/src/context.ts +150 -0
- package/src/core/helpers/rich-sanitizer.ts +7 -15
- package/src/core/types/bot-api-recent.ts +187 -0
- package/src/core/types/rich-message.ts +33 -3
- package/src/core/types/typegram.ts +1 -0
- package/src/future.ts +5 -0
- package/src/index.ts +1 -0
- package/src/telegram-types.ts +72 -0
- package/src/telegram.ts +231 -0
- package/typings/context.d.ts +66 -2
- package/typings/core/types/bot-api-recent.d.ts +153 -0
- package/typings/core/types/rich-message.d.ts +18 -1
- package/typings/core/types/typegram.d.ts +1 -0
- package/typings/index.d.ts +1 -0
- package/typings/telegram-types.d.ts +58 -1
- package/typings/telegram.d.ts +75 -0
package/lib/context.js
CHANGED
|
@@ -1153,6 +1153,117 @@ class Context {
|
|
|
1153
1153
|
this.assert(this.chat, 'deleteMessages');
|
|
1154
1154
|
return this.telegram.deleteMessages(this.chat.id, messageIds);
|
|
1155
1155
|
}
|
|
1156
|
+
// -------------------------------------------------------------------------
|
|
1157
|
+
// Bot API 10.0 - 10.3 Context Shorthands
|
|
1158
|
+
// -------------------------------------------------------------------------
|
|
1159
|
+
/**
|
|
1160
|
+
* Send a live photo to the current chat.
|
|
1161
|
+
* @see https://core.telegram.org/bots/api#sendlivephoto
|
|
1162
|
+
*/
|
|
1163
|
+
sendLivePhoto(photo, video, extra) {
|
|
1164
|
+
this.assert(this.chat, 'sendLivePhoto');
|
|
1165
|
+
return this.telegram.sendLivePhoto(this.chat.id, photo, video, extra);
|
|
1166
|
+
}
|
|
1167
|
+
/**
|
|
1168
|
+
* Reply with a live photo to the current message.
|
|
1169
|
+
* @see https://core.telegram.org/bots/api#sendlivephoto
|
|
1170
|
+
*/
|
|
1171
|
+
replyWithLivePhoto(photo, video, extra) {
|
|
1172
|
+
this.assert(this.chat, 'replyWithLivePhoto');
|
|
1173
|
+
this.assert(this.msgId, 'replyWithLivePhoto');
|
|
1174
|
+
return this.telegram.sendLivePhoto(this.chat.id, photo, video, {
|
|
1175
|
+
reply_parameters: { message_id: this.msgId },
|
|
1176
|
+
...extra,
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
/**
|
|
1180
|
+
* Edit an ephemeral message text in the current chat.
|
|
1181
|
+
* @see https://core.telegram.org/bots/api#editephemeralmessagetext
|
|
1182
|
+
*/
|
|
1183
|
+
editEphemeralMessageText(messageId, text, extra) {
|
|
1184
|
+
this.assert(this.chat, 'editEphemeralMessageText');
|
|
1185
|
+
return this.telegram.editEphemeralMessageText(this.chat.id, messageId, text, extra);
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Edit an ephemeral message media in the current chat.
|
|
1189
|
+
* @see https://core.telegram.org/bots/api#editephemeralmessagemedia
|
|
1190
|
+
*/
|
|
1191
|
+
editEphemeralMessageMedia(messageId, media, extra) {
|
|
1192
|
+
this.assert(this.chat, 'editEphemeralMessageMedia');
|
|
1193
|
+
return this.telegram.editEphemeralMessageMedia(this.chat.id, messageId, media, extra);
|
|
1194
|
+
}
|
|
1195
|
+
/**
|
|
1196
|
+
* Edit an ephemeral message caption in the current chat.
|
|
1197
|
+
* @see https://core.telegram.org/bots/api#editephemeralmessagecaption
|
|
1198
|
+
*/
|
|
1199
|
+
editEphemeralMessageCaption(messageId, extra) {
|
|
1200
|
+
this.assert(this.chat, 'editEphemeralMessageCaption');
|
|
1201
|
+
return this.telegram.editEphemeralMessageCaption(this.chat.id, messageId, extra);
|
|
1202
|
+
}
|
|
1203
|
+
/**
|
|
1204
|
+
* Edit an ephemeral message reply markup in the current chat.
|
|
1205
|
+
* @see https://core.telegram.org/bots/api#editephemeralmessagereplymarkup
|
|
1206
|
+
*/
|
|
1207
|
+
editEphemeralMessageReplyMarkup(messageId, replyMarkup) {
|
|
1208
|
+
this.assert(this.chat, 'editEphemeralMessageReplyMarkup');
|
|
1209
|
+
return this.telegram.editEphemeralMessageReplyMarkup(this.chat.id, messageId, replyMarkup);
|
|
1210
|
+
}
|
|
1211
|
+
/**
|
|
1212
|
+
* Delete an ephemeral message in the current chat.
|
|
1213
|
+
* @see https://core.telegram.org/bots/api#deleteephemeralmessage
|
|
1214
|
+
*/
|
|
1215
|
+
deleteEphemeralMessage(messageId) {
|
|
1216
|
+
this.assert(this.chat, 'deleteEphemeralMessage');
|
|
1217
|
+
const id = messageId ?? this.msgId;
|
|
1218
|
+
this.assert(id, 'deleteEphemeralMessage');
|
|
1219
|
+
return this.telegram.deleteEphemeralMessage(this.chat.id, id);
|
|
1220
|
+
}
|
|
1221
|
+
/**
|
|
1222
|
+
* Send a streaming message draft (private chats only).
|
|
1223
|
+
* @see https://core.telegram.org/bots/api#sendmessagedraft
|
|
1224
|
+
*/
|
|
1225
|
+
sendMessageDraft(draftId, text, extra) {
|
|
1226
|
+
this.assert(this.chat, 'sendMessageDraft');
|
|
1227
|
+
return this.telegram.sendMessageDraft(this.chat.id, draftId, text, extra);
|
|
1228
|
+
}
|
|
1229
|
+
/**
|
|
1230
|
+
* Delete all reactions from the current message.
|
|
1231
|
+
* @see https://core.telegram.org/bots/api#deleteallmessagereactions
|
|
1232
|
+
*/
|
|
1233
|
+
deleteAllMessageReactions(messageId) {
|
|
1234
|
+
this.assert(this.chat, 'deleteAllMessageReactions');
|
|
1235
|
+
const id = messageId ?? this.msgId;
|
|
1236
|
+
this.assert(id, 'deleteAllMessageReactions');
|
|
1237
|
+
return this.telegram.deleteAllMessageReactions(this.chat.id, id);
|
|
1238
|
+
}
|
|
1239
|
+
/**
|
|
1240
|
+
* Delete a specific reaction from the current message.
|
|
1241
|
+
* @see https://core.telegram.org/bots/api#deletemessagereaction
|
|
1242
|
+
*/
|
|
1243
|
+
deleteMessageReaction(messageId, extra) {
|
|
1244
|
+
this.assert(this.chat, 'deleteMessageReaction');
|
|
1245
|
+
const id = messageId ?? this.msgId;
|
|
1246
|
+
this.assert(id, 'deleteMessageReaction');
|
|
1247
|
+
return this.telegram.deleteMessageReaction(this.chat.id, id, extra);
|
|
1248
|
+
}
|
|
1249
|
+
/**
|
|
1250
|
+
* Answer a guest query.
|
|
1251
|
+
* @see https://core.telegram.org/bots/api#answerguestquery
|
|
1252
|
+
*/
|
|
1253
|
+
answerGuestQuery(result, extra) {
|
|
1254
|
+
const queryId = this.message?.guest_query_id;
|
|
1255
|
+
this.assert(queryId, 'answerGuestQuery');
|
|
1256
|
+
return this.telegram.answerGuestQuery(queryId, result, extra);
|
|
1257
|
+
}
|
|
1258
|
+
/**
|
|
1259
|
+
* Answer a chat join request query.
|
|
1260
|
+
* @see https://core.telegram.org/bots/api#answerchatjoinrequestquery
|
|
1261
|
+
*/
|
|
1262
|
+
answerChatJoinRequestQuery(isApproved, extra) {
|
|
1263
|
+
const queryId = this.chatJoinRequest?.query_id;
|
|
1264
|
+
this.assert(queryId, 'answerChatJoinRequestQuery');
|
|
1265
|
+
return this.telegram.answerChatJoinRequestQuery(queryId, isApproved, extra);
|
|
1266
|
+
}
|
|
1156
1267
|
/**
|
|
1157
1268
|
* @see https://core.telegram.org/bots/api#forwardmessage
|
|
1158
1269
|
*/
|
|
@@ -19,21 +19,14 @@ function formatTableToCard(tableHtml) {
|
|
|
19
19
|
}
|
|
20
20
|
if (rows.length === 0)
|
|
21
21
|
return '';
|
|
22
|
-
// Header vs Row handling (Format sebagai Kartu Elegan
|
|
22
|
+
// Header vs Row handling (Format sebagai Kartu Elegan)
|
|
23
23
|
const isKeyValue = rows.length > 0 && rows.every((r) => r.length === 2);
|
|
24
24
|
let cardText = '';
|
|
25
25
|
if (isKeyValue) {
|
|
26
26
|
const isHeaderRow = hasHeader && rows.length > 1 && (/^(parameter|informasi|metrik|field|key|unit|format|statistik|opsi|nama|item|rincian)$/i.test(rows[0][0].replace(/<[^>]*>/g, '').trim()) ||
|
|
27
27
|
/^(status|keterangan|detail|nilai|value|jumlah|estimasi|tipe|contoh input)$/i.test(rows[0][1].replace(/<[^>]*>/g, '').trim()));
|
|
28
28
|
const dataRows = isHeaderRow ? rows.slice(1) : rows;
|
|
29
|
-
const
|
|
30
|
-
const maxLen = Math.max(...dataRows.map(r => cleanKey(r[0]).length), 0);
|
|
31
|
-
const targetLen = Math.min(Math.max(maxLen, 6), 16);
|
|
32
|
-
const lines = dataRows.map((r) => {
|
|
33
|
-
const raw = cleanKey(r[0]);
|
|
34
|
-
const pad = ' '.repeat(Math.max(0, targetLen - raw.length));
|
|
35
|
-
return `<code>${raw}${pad} :</code> ${r[1]}`;
|
|
36
|
-
});
|
|
29
|
+
const lines = dataRows.map((r) => ` <b>${r[0]}:</b> ${r[1]}`);
|
|
37
30
|
cardText = `<blockquote>\n${lines.join('\n')}\n</blockquote>\n\n`;
|
|
38
31
|
}
|
|
39
32
|
else {
|
|
@@ -81,10 +81,19 @@ class RichHTMLBuilder {
|
|
|
81
81
|
this._parts.push(`<blockquote>${html}</blockquote>`);
|
|
82
82
|
return this;
|
|
83
83
|
}
|
|
84
|
+
expandableBlockQuote(html) {
|
|
85
|
+
this._parts.push(`<blockquote expandable>${html}</blockquote>`);
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
84
88
|
pullQuote(html, cite) {
|
|
85
89
|
this._parts.push(`<aside>${html}${cite ? `<cite>${cite}</cite>` : ''}</aside>`);
|
|
86
90
|
return this;
|
|
87
91
|
}
|
|
92
|
+
document(src, caption) {
|
|
93
|
+
const doc = `<tg-document src="${src}"></tg-document>`;
|
|
94
|
+
this._parts.push(caption ? `<figure>${doc}<figcaption>${caption}</figcaption></figure>` : doc);
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
88
97
|
photo(src, caption, spoiler) {
|
|
89
98
|
const img = `<img src="${src}"${spoiler ? ' tg-spoiler' : ''}/>`;
|
|
90
99
|
this._parts.push(caption ? `<figure>${img}<figcaption>${caption}</figcaption></figure>` : img);
|
|
@@ -114,7 +123,11 @@ class RichHTMLBuilder {
|
|
|
114
123
|
return this;
|
|
115
124
|
}
|
|
116
125
|
table(rows, options) {
|
|
117
|
-
const attrs = [
|
|
126
|
+
const attrs = [
|
|
127
|
+
options?.bordered && 'bordered',
|
|
128
|
+
options?.striped && 'striped',
|
|
129
|
+
options?.isCompact && 'compact',
|
|
130
|
+
]
|
|
118
131
|
.filter(Boolean)
|
|
119
132
|
.join(' ');
|
|
120
133
|
const [header, ...body] = rows;
|
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("@telegraf/types"), exports);
|
|
18
18
|
__exportStar(require("./rich-message"), exports);
|
|
19
|
+
__exportStar(require("./bot-api-recent"), exports);
|
package/lib/future.js
CHANGED
|
@@ -83,6 +83,10 @@ const replyContext = {
|
|
|
83
83
|
this.assert(this.chat, 'replyWithPhoto');
|
|
84
84
|
return this.telegram.sendPhoto(this.chat.id, photo, makeReply(this, extra));
|
|
85
85
|
},
|
|
86
|
+
replyWithLivePhoto(photo, video, extra) {
|
|
87
|
+
this.assert(this.chat, 'replyWithLivePhoto');
|
|
88
|
+
return this.telegram.sendLivePhoto(this.chat.id, photo, video, makeReply(this, extra));
|
|
89
|
+
},
|
|
86
90
|
replyWithPoll(question, options, extra) {
|
|
87
91
|
this.assert(this.chat, 'replyWithPoll');
|
|
88
92
|
return this.telegram.sendPoll(this.chat.id, question, options, makeReply(this, extra));
|
|
@@ -160,6 +164,7 @@ function useNewReplies() {
|
|
|
160
164
|
ctx.replyWithHTML = replyContext.replyWithHTML;
|
|
161
165
|
ctx.replyWithRichMessage = replyContext.replyWithRichMessage;
|
|
162
166
|
ctx.replyWithRichMessageContent = replyContext.replyWithRichMessageContent;
|
|
167
|
+
ctx.replyWithLivePhoto = replyContext.replyWithLivePhoto;
|
|
163
168
|
return next();
|
|
164
169
|
};
|
|
165
170
|
}
|
package/lib/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.InputBox = exports.FormScene = exports.PaginatedBuilder = exports.sanitizeRichHtml = exports.AIStreamAdapter = exports.SmartQueue = exports.MD = exports.HTML = exports.RichMarkdownBuilder = exports.RichHTMLBuilder = exports.RichMessage = exports.Scenes = exports.MemorySessionStore = exports.session = exports.deunionize = exports.Format = exports.Input = exports.Markup = exports.Types = exports.Telegram = exports.TelegramError = exports.Router = exports.Composer = exports.Context = exports.Telegraf = void 0;
|
|
26
|
+
exports.InputBox = exports.FormScene = exports.PaginatedBuilder = exports.sanitizeRichHtml = exports.AIStreamAdapter = exports.SmartQueue = exports.MD = exports.HTML = exports.RichMarkdownBuilder = exports.RichHTMLBuilder = exports.RecentTypes = exports.RichMessage = exports.Scenes = exports.MemorySessionStore = exports.session = exports.deunionize = exports.Format = exports.Input = exports.Markup = exports.Types = exports.Telegram = exports.TelegramError = exports.Router = exports.Composer = exports.Context = exports.Telegraf = void 0;
|
|
27
27
|
var telegraf_1 = require("./telegraf");
|
|
28
28
|
Object.defineProperty(exports, "Telegraf", { enumerable: true, get: function () { return telegraf_1.Telegraf; } });
|
|
29
29
|
var context_1 = require("./context");
|
|
@@ -47,6 +47,7 @@ Object.defineProperty(exports, "session", { enumerable: true, get: function () {
|
|
|
47
47
|
Object.defineProperty(exports, "MemorySessionStore", { enumerable: true, get: function () { return session_1.MemorySessionStore; } });
|
|
48
48
|
exports.Scenes = __importStar(require("./scenes"));
|
|
49
49
|
exports.RichMessage = __importStar(require("./core/types/rich-message"));
|
|
50
|
+
exports.RecentTypes = __importStar(require("./core/types/bot-api-recent"));
|
|
50
51
|
var rich_message_1 = require("./core/types/rich-message");
|
|
51
52
|
Object.defineProperty(exports, "RichHTMLBuilder", { enumerable: true, get: function () { return rich_message_1.RichHTMLBuilder; } });
|
|
52
53
|
Object.defineProperty(exports, "RichMarkdownBuilder", { enumerable: true, get: function () { return rich_message_1.RichMarkdownBuilder; } });
|
package/lib/telegram.js
CHANGED
|
@@ -1352,6 +1352,173 @@ class Telegram extends client_1.default {
|
|
|
1352
1352
|
throw err;
|
|
1353
1353
|
}
|
|
1354
1354
|
}
|
|
1355
|
+
// -------------------------------------------------------------------------
|
|
1356
|
+
// Bot API 10.0 - 10.3 Methods
|
|
1357
|
+
// -------------------------------------------------------------------------
|
|
1358
|
+
/**
|
|
1359
|
+
* Send a live photo (photo with short video).
|
|
1360
|
+
* @see https://core.telegram.org/bots/api#sendlivephoto
|
|
1361
|
+
*/
|
|
1362
|
+
sendLivePhoto(chatId, photo, video, extra) {
|
|
1363
|
+
return this.callApi('sendLivePhoto', {
|
|
1364
|
+
chat_id: chatId,
|
|
1365
|
+
photo,
|
|
1366
|
+
video,
|
|
1367
|
+
...extra,
|
|
1368
|
+
});
|
|
1369
|
+
}
|
|
1370
|
+
/**
|
|
1371
|
+
* Edit an ephemeral message text.
|
|
1372
|
+
* @see https://core.telegram.org/bots/api#editephemeralmessagetext
|
|
1373
|
+
*/
|
|
1374
|
+
editEphemeralMessageText(chatId, messageId, text, extra) {
|
|
1375
|
+
return this.callApi('editEphemeralMessageText', {
|
|
1376
|
+
chat_id: chatId,
|
|
1377
|
+
message_id: messageId,
|
|
1378
|
+
text,
|
|
1379
|
+
...extra,
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1382
|
+
/**
|
|
1383
|
+
* Edit an ephemeral message media.
|
|
1384
|
+
* @see https://core.telegram.org/bots/api#editephemeralmessagemedia
|
|
1385
|
+
*/
|
|
1386
|
+
editEphemeralMessageMedia(chatId, messageId, media, extra) {
|
|
1387
|
+
return this.callApi('editEphemeralMessageMedia', {
|
|
1388
|
+
chat_id: chatId,
|
|
1389
|
+
message_id: messageId,
|
|
1390
|
+
media,
|
|
1391
|
+
...extra,
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
/**
|
|
1395
|
+
* Edit an ephemeral message caption.
|
|
1396
|
+
* @see https://core.telegram.org/bots/api#editephemeralmessagecaption
|
|
1397
|
+
*/
|
|
1398
|
+
editEphemeralMessageCaption(chatId, messageId, extra) {
|
|
1399
|
+
return this.callApi('editEphemeralMessageCaption', {
|
|
1400
|
+
chat_id: chatId,
|
|
1401
|
+
message_id: messageId,
|
|
1402
|
+
...extra,
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1405
|
+
/**
|
|
1406
|
+
* Edit an ephemeral message reply markup.
|
|
1407
|
+
* @see https://core.telegram.org/bots/api#editephemeralmessagereplymarkup
|
|
1408
|
+
*/
|
|
1409
|
+
editEphemeralMessageReplyMarkup(chatId, messageId, replyMarkup) {
|
|
1410
|
+
return this.callApi('editEphemeralMessageReplyMarkup', {
|
|
1411
|
+
chat_id: chatId,
|
|
1412
|
+
message_id: messageId,
|
|
1413
|
+
reply_markup: replyMarkup,
|
|
1414
|
+
});
|
|
1415
|
+
}
|
|
1416
|
+
/**
|
|
1417
|
+
* Delete an ephemeral message.
|
|
1418
|
+
* @see https://core.telegram.org/bots/api#deleteephemeralmessage
|
|
1419
|
+
*/
|
|
1420
|
+
deleteEphemeralMessage(chatId, messageId) {
|
|
1421
|
+
return this.callApi('deleteEphemeralMessage', {
|
|
1422
|
+
chat_id: chatId,
|
|
1423
|
+
message_id: messageId,
|
|
1424
|
+
});
|
|
1425
|
+
}
|
|
1426
|
+
/**
|
|
1427
|
+
* Send a streaming message draft (private chats only).
|
|
1428
|
+
* @see https://core.telegram.org/bots/api#sendmessagedraft
|
|
1429
|
+
*/
|
|
1430
|
+
sendMessageDraft(chatId, draftId, text, extra) {
|
|
1431
|
+
return this.callApi('sendMessageDraft', {
|
|
1432
|
+
chat_id: chatId,
|
|
1433
|
+
draft_id: draftId,
|
|
1434
|
+
text,
|
|
1435
|
+
...extra,
|
|
1436
|
+
});
|
|
1437
|
+
}
|
|
1438
|
+
/**
|
|
1439
|
+
* Answer a guest query.
|
|
1440
|
+
* @see https://core.telegram.org/bots/api#answerguestquery
|
|
1441
|
+
*/
|
|
1442
|
+
answerGuestQuery(guestQueryId, result, extra) {
|
|
1443
|
+
return this.callApi('answerGuestQuery', {
|
|
1444
|
+
guest_query_id: guestQueryId,
|
|
1445
|
+
result,
|
|
1446
|
+
...extra,
|
|
1447
|
+
});
|
|
1448
|
+
}
|
|
1449
|
+
/**
|
|
1450
|
+
* Answer a chat join request query.
|
|
1451
|
+
* @see https://core.telegram.org/bots/api#answerchatjoinrequestquery
|
|
1452
|
+
*/
|
|
1453
|
+
answerChatJoinRequestQuery(queryId, isApproved, extra) {
|
|
1454
|
+
return this.callApi('answerChatJoinRequestQuery', {
|
|
1455
|
+
query_id: queryId,
|
|
1456
|
+
is_approved: isApproved,
|
|
1457
|
+
...extra,
|
|
1458
|
+
});
|
|
1459
|
+
}
|
|
1460
|
+
/**
|
|
1461
|
+
* Send a Web App to verify or complete a chat join request.
|
|
1462
|
+
* @see https://core.telegram.org/bots/api#sendchatjoinrequestwebapp
|
|
1463
|
+
*/
|
|
1464
|
+
sendChatJoinRequestWebApp(queryId, webAppUrl, extra) {
|
|
1465
|
+
return this.callApi('sendChatJoinRequestWebApp', {
|
|
1466
|
+
query_id: queryId,
|
|
1467
|
+
web_app_url: webAppUrl,
|
|
1468
|
+
...extra,
|
|
1469
|
+
});
|
|
1470
|
+
}
|
|
1471
|
+
/**
|
|
1472
|
+
* Delete all reactions from a message.
|
|
1473
|
+
* @see https://core.telegram.org/bots/api#deleteallmessagereactions
|
|
1474
|
+
*/
|
|
1475
|
+
deleteAllMessageReactions(chatId, messageId) {
|
|
1476
|
+
return this.callApi('deleteAllMessageReactions', {
|
|
1477
|
+
chat_id: chatId,
|
|
1478
|
+
message_id: messageId,
|
|
1479
|
+
});
|
|
1480
|
+
}
|
|
1481
|
+
/**
|
|
1482
|
+
* Delete a specific reaction on a message.
|
|
1483
|
+
* @see https://core.telegram.org/bots/api#deletemessagereaction
|
|
1484
|
+
*/
|
|
1485
|
+
deleteMessageReaction(chatId, messageId, extra) {
|
|
1486
|
+
return this.callApi('deleteMessageReaction', {
|
|
1487
|
+
chat_id: chatId,
|
|
1488
|
+
message_id: messageId,
|
|
1489
|
+
...extra,
|
|
1490
|
+
});
|
|
1491
|
+
}
|
|
1492
|
+
/**
|
|
1493
|
+
* Get access settings for a managed secretary bot.
|
|
1494
|
+
* @see https://core.telegram.org/bots/api#getmanagedbotaccesssettings
|
|
1495
|
+
*/
|
|
1496
|
+
getManagedBotAccessSettings(userId) {
|
|
1497
|
+
return this.callApi('getManagedBotAccessSettings', {
|
|
1498
|
+
user_id: userId,
|
|
1499
|
+
});
|
|
1500
|
+
}
|
|
1501
|
+
/**
|
|
1502
|
+
* Set access settings for a managed secretary bot.
|
|
1503
|
+
* @see https://core.telegram.org/bots/api#setmanagedbotaccesssettings
|
|
1504
|
+
*/
|
|
1505
|
+
setManagedBotAccessSettings(userId, settings) {
|
|
1506
|
+
return this.callApi('setManagedBotAccessSettings', {
|
|
1507
|
+
user_id: userId,
|
|
1508
|
+
...settings,
|
|
1509
|
+
});
|
|
1510
|
+
}
|
|
1511
|
+
/**
|
|
1512
|
+
* Get personal chat messages managed by a secretary bot.
|
|
1513
|
+
* @see https://core.telegram.org/bots/api#getuserpersonalchatmessages
|
|
1514
|
+
*/
|
|
1515
|
+
getUserPersonalChatMessages(userId, chatId, messageIds) {
|
|
1516
|
+
return this.callApi('getUserPersonalChatMessages', {
|
|
1517
|
+
user_id: userId,
|
|
1518
|
+
chat_id: chatId,
|
|
1519
|
+
message_ids: messageIds,
|
|
1520
|
+
});
|
|
1521
|
+
}
|
|
1355
1522
|
}
|
|
1356
1523
|
exports.Telegram = Telegram;
|
|
1357
1524
|
exports.default = Telegram;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "teledzik",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Modern Telegram Bot Framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"telekaf",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"botapi",
|
|
13
13
|
"bot framework",
|
|
14
14
|
"rich messages",
|
|
15
|
-
"bot api
|
|
15
|
+
"bot api 10.3"
|
|
16
16
|
],
|
|
17
17
|
"homepage": "https://telegraf.js.org",
|
|
18
18
|
"bugs": {
|
package/src/context.ts
CHANGED
|
@@ -1509,6 +1509,156 @@ export class Context<U extends Deunionize<tg.Update> = tg.Update> {
|
|
|
1509
1509
|
return this.telegram.deleteMessages(this.chat.id, messageIds)
|
|
1510
1510
|
}
|
|
1511
1511
|
|
|
1512
|
+
// -------------------------------------------------------------------------
|
|
1513
|
+
// Bot API 10.0 - 10.3 Context Shorthands
|
|
1514
|
+
// -------------------------------------------------------------------------
|
|
1515
|
+
|
|
1516
|
+
/**
|
|
1517
|
+
* Send a live photo to the current chat.
|
|
1518
|
+
* @see https://core.telegram.org/bots/api#sendlivephoto
|
|
1519
|
+
*/
|
|
1520
|
+
sendLivePhoto(
|
|
1521
|
+
photo: tg.InputFile | string,
|
|
1522
|
+
video: tg.InputFile | string,
|
|
1523
|
+
extra?: tt.ExtraSendLivePhoto
|
|
1524
|
+
) {
|
|
1525
|
+
this.assert(this.chat, 'sendLivePhoto')
|
|
1526
|
+
return this.telegram.sendLivePhoto(this.chat.id, photo, video, extra)
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
/**
|
|
1530
|
+
* Reply with a live photo to the current message.
|
|
1531
|
+
* @see https://core.telegram.org/bots/api#sendlivephoto
|
|
1532
|
+
*/
|
|
1533
|
+
replyWithLivePhoto(
|
|
1534
|
+
photo: tg.InputFile | string,
|
|
1535
|
+
video: tg.InputFile | string,
|
|
1536
|
+
extra?: tt.ExtraSendLivePhoto
|
|
1537
|
+
) {
|
|
1538
|
+
this.assert(this.chat, 'replyWithLivePhoto')
|
|
1539
|
+
this.assert(this.msgId, 'replyWithLivePhoto')
|
|
1540
|
+
return this.telegram.sendLivePhoto(this.chat.id, photo, video, {
|
|
1541
|
+
reply_parameters: { message_id: this.msgId },
|
|
1542
|
+
...extra,
|
|
1543
|
+
})
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
/**
|
|
1547
|
+
* Edit an ephemeral message text in the current chat.
|
|
1548
|
+
* @see https://core.telegram.org/bots/api#editephemeralmessagetext
|
|
1549
|
+
*/
|
|
1550
|
+
editEphemeralMessageText(
|
|
1551
|
+
messageId: number,
|
|
1552
|
+
text: string,
|
|
1553
|
+
extra?: tt.ExtraEditEphemeralMessageText
|
|
1554
|
+
) {
|
|
1555
|
+
this.assert(this.chat, 'editEphemeralMessageText')
|
|
1556
|
+
return this.telegram.editEphemeralMessageText(this.chat.id, messageId, text, extra)
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1559
|
+
/**
|
|
1560
|
+
* Edit an ephemeral message media in the current chat.
|
|
1561
|
+
* @see https://core.telegram.org/bots/api#editephemeralmessagemedia
|
|
1562
|
+
*/
|
|
1563
|
+
editEphemeralMessageMedia(
|
|
1564
|
+
messageId: number,
|
|
1565
|
+
media: tg.InputMedia,
|
|
1566
|
+
extra?: tt.ExtraEditEphemeralMessageMedia
|
|
1567
|
+
) {
|
|
1568
|
+
this.assert(this.chat, 'editEphemeralMessageMedia')
|
|
1569
|
+
return this.telegram.editEphemeralMessageMedia(this.chat.id, messageId, media, extra)
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
/**
|
|
1573
|
+
* Edit an ephemeral message caption in the current chat.
|
|
1574
|
+
* @see https://core.telegram.org/bots/api#editephemeralmessagecaption
|
|
1575
|
+
*/
|
|
1576
|
+
editEphemeralMessageCaption(
|
|
1577
|
+
messageId: number,
|
|
1578
|
+
extra?: tt.ExtraEditEphemeralMessageCaption
|
|
1579
|
+
) {
|
|
1580
|
+
this.assert(this.chat, 'editEphemeralMessageCaption')
|
|
1581
|
+
return this.telegram.editEphemeralMessageCaption(this.chat.id, messageId, extra)
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
/**
|
|
1585
|
+
* Edit an ephemeral message reply markup in the current chat.
|
|
1586
|
+
* @see https://core.telegram.org/bots/api#editephemeralmessagereplymarkup
|
|
1587
|
+
*/
|
|
1588
|
+
editEphemeralMessageReplyMarkup(
|
|
1589
|
+
messageId: number,
|
|
1590
|
+
replyMarkup?: tg.InlineKeyboardMarkup
|
|
1591
|
+
) {
|
|
1592
|
+
this.assert(this.chat, 'editEphemeralMessageReplyMarkup')
|
|
1593
|
+
return this.telegram.editEphemeralMessageReplyMarkup(this.chat.id, messageId, replyMarkup)
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
/**
|
|
1597
|
+
* Delete an ephemeral message in the current chat.
|
|
1598
|
+
* @see https://core.telegram.org/bots/api#deleteephemeralmessage
|
|
1599
|
+
*/
|
|
1600
|
+
deleteEphemeralMessage(messageId?: number) {
|
|
1601
|
+
this.assert(this.chat, 'deleteEphemeralMessage')
|
|
1602
|
+
const id = messageId ?? this.msgId
|
|
1603
|
+
this.assert(id, 'deleteEphemeralMessage')
|
|
1604
|
+
return this.telegram.deleteEphemeralMessage(this.chat.id, id)
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
/**
|
|
1608
|
+
* Send a streaming message draft (private chats only).
|
|
1609
|
+
* @see https://core.telegram.org/bots/api#sendmessagedraft
|
|
1610
|
+
*/
|
|
1611
|
+
sendMessageDraft(
|
|
1612
|
+
draftId: number,
|
|
1613
|
+
text: string,
|
|
1614
|
+
extra?: tt.ExtraSendMessageDraft
|
|
1615
|
+
) {
|
|
1616
|
+
this.assert(this.chat, 'sendMessageDraft')
|
|
1617
|
+
return this.telegram.sendMessageDraft(this.chat.id as number, draftId, text, extra)
|
|
1618
|
+
}
|
|
1619
|
+
|
|
1620
|
+
/**
|
|
1621
|
+
* Delete all reactions from the current message.
|
|
1622
|
+
* @see https://core.telegram.org/bots/api#deleteallmessagereactions
|
|
1623
|
+
*/
|
|
1624
|
+
deleteAllMessageReactions(messageId?: number) {
|
|
1625
|
+
this.assert(this.chat, 'deleteAllMessageReactions')
|
|
1626
|
+
const id = messageId ?? this.msgId
|
|
1627
|
+
this.assert(id, 'deleteAllMessageReactions')
|
|
1628
|
+
return this.telegram.deleteAllMessageReactions(this.chat.id, id)
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
/**
|
|
1632
|
+
* Delete a specific reaction from the current message.
|
|
1633
|
+
* @see https://core.telegram.org/bots/api#deletemessagereaction
|
|
1634
|
+
*/
|
|
1635
|
+
deleteMessageReaction(messageId?: number, extra?: tt.ExtraDeleteMessageReaction) {
|
|
1636
|
+
this.assert(this.chat, 'deleteMessageReaction')
|
|
1637
|
+
const id = messageId ?? this.msgId
|
|
1638
|
+
this.assert(id, 'deleteMessageReaction')
|
|
1639
|
+
return this.telegram.deleteMessageReaction(this.chat.id, id, extra)
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
/**
|
|
1643
|
+
* Answer a guest query.
|
|
1644
|
+
* @see https://core.telegram.org/bots/api#answerguestquery
|
|
1645
|
+
*/
|
|
1646
|
+
answerGuestQuery(result: any, extra?: tt.ExtraAnswerGuestQuery) {
|
|
1647
|
+
const queryId = (this.message as any)?.guest_query_id
|
|
1648
|
+
this.assert(queryId, 'answerGuestQuery')
|
|
1649
|
+
return this.telegram.answerGuestQuery(queryId, result, extra)
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
/**
|
|
1653
|
+
* Answer a chat join request query.
|
|
1654
|
+
* @see https://core.telegram.org/bots/api#answerchatjoinrequestquery
|
|
1655
|
+
*/
|
|
1656
|
+
answerChatJoinRequestQuery(isApproved: boolean, extra?: tt.ExtraAnswerChatJoinRequestQuery) {
|
|
1657
|
+
const queryId = (this.chatJoinRequest as any)?.query_id
|
|
1658
|
+
this.assert(queryId, 'answerChatJoinRequestQuery')
|
|
1659
|
+
return this.telegram.answerChatJoinRequestQuery(queryId, isApproved, extra)
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1512
1662
|
/**
|
|
1513
1663
|
* @see https://core.telegram.org/bots/api#forwardmessage
|
|
1514
1664
|
*/
|
|
@@ -14,25 +14,17 @@ function formatTableToCard(tableHtml: string): string {
|
|
|
14
14
|
}
|
|
15
15
|
if (rows.length === 0) return ''
|
|
16
16
|
|
|
17
|
-
// Header vs Row handling (Format sebagai Kartu Elegan
|
|
18
|
-
const isKeyValue = rows.length > 0 && rows.every((r) => r.length === 2)
|
|
19
|
-
let cardText = ''
|
|
17
|
+
// Header vs Row handling (Format sebagai Kartu Elegan)
|
|
18
|
+
const isKeyValue = rows.length > 0 && rows.every((r) => r.length === 2)
|
|
19
|
+
let cardText = ''
|
|
20
20
|
if (isKeyValue) {
|
|
21
21
|
const isHeaderRow = hasHeader && rows.length > 1 && (
|
|
22
22
|
/^(parameter|informasi|metrik|field|key|unit|format|statistik|opsi|nama|item|rincian)$/i.test(rows[0][0].replace(/<[^>]*>/g, '').trim()) ||
|
|
23
23
|
/^(status|keterangan|detail|nilai|value|jumlah|estimasi|tipe|contoh input)$/i.test(rows[0][1].replace(/<[^>]*>/g, '').trim())
|
|
24
|
-
)
|
|
25
|
-
const dataRows = isHeaderRow ? rows.slice(1) : rows
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
const targetLen = Math.min(Math.max(maxLen, 6), 16);
|
|
29
|
-
|
|
30
|
-
const lines = dataRows.map((r) => {
|
|
31
|
-
const raw = cleanKey(r[0]);
|
|
32
|
-
const pad = ' '.repeat(Math.max(0, targetLen - raw.length));
|
|
33
|
-
return `<code>${raw}${pad} :</code> ${r[1]}`;
|
|
34
|
-
});
|
|
35
|
-
cardText = `<blockquote>\n${lines.join('\n')}\n</blockquote>\n\n`;
|
|
24
|
+
)
|
|
25
|
+
const dataRows = isHeaderRow ? rows.slice(1) : rows
|
|
26
|
+
const lines = dataRows.map((r) => ` <b>${r[0]}:</b> ${r[1]}`)
|
|
27
|
+
cardText = `<blockquote>\n${lines.join('\n')}\n</blockquote>\n\n`
|
|
36
28
|
} else {
|
|
37
29
|
const lines = rows.map((r, idx) => {
|
|
38
30
|
if (idx === 0 && hasHeader) return `<b>${r.join(' │ ')}</b>`
|