teledzik 1.0.3 â 1.0.5
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 +75 -5
- package/lib/button.js +48 -5
- package/lib/context.js +34 -9
- package/lib/index.js +6 -1
- package/lib/telegram.js +90 -11
- package/package.json +2 -2
- package/src/button.ts +89 -6
- package/src/context.ts +60 -20
- package/src/core/types/rich-message.ts +15 -0
- package/src/index.ts +1 -0
- package/src/telegram.ts +117 -13
- package/typings/button.d.ts +51 -2
- package/typings/context.d.ts +4 -2
- package/typings/core/types/rich-message.d.ts +20 -0
- package/typings/index.d.ts +1 -0
- package/typings/telegram.d.ts +4 -2
- package/src/filters.js +0 -69
- package/src/format.js +0 -38
- package/src/future.js +0 -147
- package/src/markup.js +0 -93
- package/src/scenes.js +0 -17
- package/src/session.js +0 -175
- package/src/types.js +0 -2
- package/src/utils.js +0 -5
package/README.md
CHANGED
|
@@ -467,7 +467,7 @@ const msg = new MD()
|
|
|
467
467
|
.details('Expand me', '### Hidden heading\n\n- item 1\n- item 2')
|
|
468
468
|
.divider()
|
|
469
469
|
.paragraph('See footnote' + MD.sup('[1]'))
|
|
470
|
-
.footnote('1', MD.url('https://t.me/
|
|
470
|
+
.footnote('1', MD.url('https://t.me/lorddzik', '@lorddzik'))
|
|
471
471
|
.build()
|
|
472
472
|
```
|
|
473
473
|
|
|
@@ -526,7 +526,7 @@ bot.command('ai', async (ctx) => {
|
|
|
526
526
|
.heading(2, 'đ¤ AI Response')
|
|
527
527
|
.paragraph('Here is the final answer from the AI.')
|
|
528
528
|
.divider()
|
|
529
|
-
.footer(HTML.url('https://t.me/
|
|
529
|
+
.footer(HTML.url('https://t.me/lorddzik', '@lorddzik'))
|
|
530
530
|
.build()
|
|
531
531
|
)
|
|
532
532
|
})
|
|
@@ -564,7 +564,7 @@ await ctx.sendRichMessage(msg, {
|
|
|
564
564
|
Markup.button.callback('â
Yes', 'answer:yes'),
|
|
565
565
|
Markup.button.callback('â No', 'answer:no'),
|
|
566
566
|
],
|
|
567
|
-
[Markup.button.url('đ Visit', 'https://t.me/
|
|
567
|
+
[Markup.button.url('đ Visit', 'https://t.me/lorddzik')],
|
|
568
568
|
]).reply_markup,
|
|
569
569
|
})
|
|
570
570
|
|
|
@@ -588,6 +588,43 @@ await ctx.sendRichMessage(msg, {
|
|
|
588
588
|
|
|
589
589
|
---
|
|
590
590
|
|
|
591
|
+
### Universal `editRichMessage` (Omni-Format Support)
|
|
592
|
+
|
|
593
|
+
Update existing messages or media captions in-place with **any** content format. It automatically detects Text vs Media (Photo/Video/Audio/Doc) and silently handles Telegram's `message is not modified` without throwing errors:
|
|
594
|
+
|
|
595
|
+
```ts
|
|
596
|
+
import { Telegraf, RichHTMLBuilder, Markup } from 'teledzik'
|
|
597
|
+
|
|
598
|
+
bot.action('btn:update', async (ctx) => {
|
|
599
|
+
// 1. Using RichHTMLBuilder instance directly
|
|
600
|
+
const rich = new RichHTMLBuilder()
|
|
601
|
+
.heading(1, '⥠Server Stats Updated')
|
|
602
|
+
.table([
|
|
603
|
+
['Node', 'RAM', 'Status'],
|
|
604
|
+
['VPS-01', '3.8 GB', 'ONLINE đĸ'],
|
|
605
|
+
['VPS-02', '7.2 GB', 'ONLINE đĸ']
|
|
606
|
+
], { bordered: true, striped: true, hasHeader: true })
|
|
607
|
+
|
|
608
|
+
await ctx.editRichMessage(rich, {
|
|
609
|
+
reply_markup: Markup.inlineKeyboard([
|
|
610
|
+
[Markup.button.primary('đ Refresh', 'btn:update')]
|
|
611
|
+
]).reply_markup
|
|
612
|
+
})
|
|
613
|
+
|
|
614
|
+
// 2. Or using an Object
|
|
615
|
+
await ctx.editRichMessage({
|
|
616
|
+
html: '<b>New Content</b>',
|
|
617
|
+
reply_markup: { inline_keyboard: [] }
|
|
618
|
+
})
|
|
619
|
+
|
|
620
|
+
// 3. Or using Raw HTML String
|
|
621
|
+
await ctx.editRichMessage('<b>Updated via raw string</b>')
|
|
622
|
+
|
|
623
|
+
// 4. Or specifying a custom messageId
|
|
624
|
+
await ctx.editRichMessage(12345, '<b>Edit specific message ID</b>')
|
|
625
|
+
})
|
|
626
|
+
```
|
|
627
|
+
|
|
591
628
|
### Inline / Web App Queries
|
|
592
629
|
|
|
593
630
|
Use `InputRichMessageContent` as `input_message_content` in inline query results:
|
|
@@ -600,7 +637,7 @@ bot.on('inline_query', async (ctx) => {
|
|
|
600
637
|
const richContent: RichMessage.InputRichMessageContent = {
|
|
601
638
|
rich_message: new HTML()
|
|
602
639
|
.heading(1, 'Result from Inline Query')
|
|
603
|
-
.paragraph('Sent via ' + HTML.url('https://t.me/
|
|
640
|
+
.paragraph('Sent via ' + HTML.url('https://t.me/lorddzik', '@lorddzik') + '.')
|
|
604
641
|
.build(),
|
|
605
642
|
}
|
|
606
643
|
|
|
@@ -1117,10 +1154,43 @@ bot.use((ctx, next) => {
|
|
|
1117
1154
|
```
|
|
1118
1155
|
|
|
1119
1156
|
|
|
1157
|
+
### Native Colored Buttons (Telegram Bot API 9.4+)
|
|
1158
|
+
|
|
1159
|
+
Teledzik provides first-class support for native Telegram button background colors (`primary` Blue, `success` Green, `danger` Red) on inline keyboards:
|
|
1160
|
+
|
|
1161
|
+
```ts
|
|
1162
|
+
import { Markup } from 'teledzik'
|
|
1163
|
+
|
|
1164
|
+
const keyboard = Markup.inlineKeyboard([
|
|
1165
|
+
// đĩ Blue Background (Primary action)
|
|
1166
|
+
[Markup.button.primary('âšī¸ Bantuan', 'help')],
|
|
1167
|
+
|
|
1168
|
+
// đĸ Green Background (Success / positive action)
|
|
1169
|
+
[Markup.button.success('đ Status Build', 'status')],
|
|
1170
|
+
|
|
1171
|
+
// đ´ Red Background (Danger / destructive action)
|
|
1172
|
+
[Markup.button.danger('đ Perintah / Hapus', 'commands')],
|
|
1173
|
+
|
|
1174
|
+
// đĩ Native Styled URL Buttons
|
|
1175
|
+
[
|
|
1176
|
+
Markup.button.primaryUrl('đ Owner', 'https://t.me/LordDzik'),
|
|
1177
|
+
Markup.button.primaryUrl('âšī¸ Information', 'https://t.me/LordDzik')
|
|
1178
|
+
],
|
|
1179
|
+
|
|
1180
|
+
// đĸ Green & đ´ Red URL Buttons
|
|
1181
|
+
[
|
|
1182
|
+
Markup.button.successUrl('â
Website', 'https://example.com'),
|
|
1183
|
+
Markup.button.dangerUrl('đ¨ Report', 'https://example.com/report')
|
|
1184
|
+
]
|
|
1185
|
+
])
|
|
1186
|
+
|
|
1187
|
+
await ctx.reply('Menu:', keyboard)
|
|
1188
|
+
```
|
|
1189
|
+
|
|
1120
1190
|
---
|
|
1121
1191
|
|
|
1122
1192
|
## Author & Maintainer
|
|
1123
1193
|
|
|
1124
|
-
This fork is maintained by **@
|
|
1194
|
+
This fork is maintained by **@lorddzik** â [t.me/lorddzik](https://t.me/lorddzik)
|
|
1125
1195
|
|
|
1126
1196
|
Upstream project: [telegraf/telegraf](https://github.com/telegraf/telegraf) by The Telegraf Contributors.
|
package/lib/button.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.webApp = exports.login = exports.pay = exports.game = exports.switchToCurrentChat = exports.switchToChat = exports.callback = exports.url = exports.channelRequest = exports.groupRequest = exports.botRequest = exports.userRequest = exports.pollRequest = exports.locationRequest = exports.contactRequest = exports.text = void 0;
|
|
3
|
+
exports.dangerUrl = exports.successUrl = exports.primaryUrl = exports.danger = exports.success = exports.primary = exports.webApp = exports.login = exports.pay = exports.game = exports.switchToCurrentChat = exports.switchToChat = exports.callback = exports.url = exports.channelRequest = exports.groupRequest = exports.botRequest = exports.userRequest = exports.pollRequest = exports.locationRequest = exports.contactRequest = exports.text = void 0;
|
|
4
4
|
function text(text, hide = false) {
|
|
5
5
|
return { text, hide };
|
|
6
6
|
}
|
|
@@ -57,12 +57,12 @@ request_id, extra, hide = false) {
|
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
exports.channelRequest = channelRequest;
|
|
60
|
-
function url(text, url, hide = false) {
|
|
61
|
-
return { text, url, hide };
|
|
60
|
+
function url(text, url, hide = false, style, icon_custom_emoji_id) {
|
|
61
|
+
return { text, url, hide, ...(style ? { style } : {}), ...(icon_custom_emoji_id ? { icon_custom_emoji_id } : {}) };
|
|
62
62
|
}
|
|
63
63
|
exports.url = url;
|
|
64
|
-
function callback(text, data, hide = false) {
|
|
65
|
-
return { text, callback_data: data, hide };
|
|
64
|
+
function callback(text, data, hide = false, style, icon_custom_emoji_id) {
|
|
65
|
+
return { text, callback_data: data, hide, ...(style ? { style } : {}), ...(icon_custom_emoji_id ? { icon_custom_emoji_id } : {}) };
|
|
66
66
|
}
|
|
67
67
|
exports.callback = callback;
|
|
68
68
|
function switchToChat(text, value, hide = false) {
|
|
@@ -99,3 +99,46 @@ function webApp(text, url, hide = false
|
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
101
|
exports.webApp = webApp;
|
|
102
|
+
// ââ Native Telegram Background Color Buttons (Bot API 9.4+) âââââââââââââââ
|
|
103
|
+
/**
|
|
104
|
+
* đĩ Primary callback button (Blue background)
|
|
105
|
+
*/
|
|
106
|
+
function primary(text, data, hide = false, icon_custom_emoji_id) {
|
|
107
|
+
return callback(text, data, hide, 'primary', icon_custom_emoji_id);
|
|
108
|
+
}
|
|
109
|
+
exports.primary = primary;
|
|
110
|
+
/**
|
|
111
|
+
* đĸ Success callback button (Green background)
|
|
112
|
+
*/
|
|
113
|
+
function success(text, data, hide = false, icon_custom_emoji_id) {
|
|
114
|
+
return callback(text, data, hide, 'success', icon_custom_emoji_id);
|
|
115
|
+
}
|
|
116
|
+
exports.success = success;
|
|
117
|
+
/**
|
|
118
|
+
* đ´ Danger / Delete callback button (Red background)
|
|
119
|
+
*/
|
|
120
|
+
function danger(text, data, hide = false, icon_custom_emoji_id) {
|
|
121
|
+
return callback(text, data, hide, 'danger', icon_custom_emoji_id);
|
|
122
|
+
}
|
|
123
|
+
exports.danger = danger;
|
|
124
|
+
/**
|
|
125
|
+
* đĩ Primary URL button (Blue background)
|
|
126
|
+
*/
|
|
127
|
+
function primaryUrl(text, targetUrl, hide = false, icon_custom_emoji_id) {
|
|
128
|
+
return url(text, targetUrl, hide, 'primary', icon_custom_emoji_id);
|
|
129
|
+
}
|
|
130
|
+
exports.primaryUrl = primaryUrl;
|
|
131
|
+
/**
|
|
132
|
+
* đĸ Success URL button (Green background)
|
|
133
|
+
*/
|
|
134
|
+
function successUrl(text, targetUrl, hide = false, icon_custom_emoji_id) {
|
|
135
|
+
return url(text, targetUrl, hide, 'success', icon_custom_emoji_id);
|
|
136
|
+
}
|
|
137
|
+
exports.successUrl = successUrl;
|
|
138
|
+
/**
|
|
139
|
+
* đ´ Danger URL button (Red background)
|
|
140
|
+
*/
|
|
141
|
+
function dangerUrl(text, targetUrl, hide = false, icon_custom_emoji_id) {
|
|
142
|
+
return url(text, targetUrl, hide, 'danger', icon_custom_emoji_id);
|
|
143
|
+
}
|
|
144
|
+
exports.dangerUrl = dangerUrl;
|
package/lib/context.js
CHANGED
|
@@ -1069,12 +1069,39 @@ class Context {
|
|
|
1069
1069
|
this.assert(this.chat, 'sendRichMessageDraft');
|
|
1070
1070
|
return this.telegram.sendRichMessageDraft(this.chat.id, draftId, richMessage, extra);
|
|
1071
1071
|
}
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1072
|
+
async editRichMessage(a, b, c) {
|
|
1073
|
+
let targetMsgId;
|
|
1074
|
+
let content;
|
|
1075
|
+
let extra = {};
|
|
1076
|
+
if (typeof a === 'number' ||
|
|
1077
|
+
(typeof a === 'string' && !isNaN(Number(a)) && b !== undefined)) {
|
|
1078
|
+
targetMsgId = a;
|
|
1079
|
+
content = b;
|
|
1080
|
+
extra = c || {};
|
|
1081
|
+
}
|
|
1082
|
+
else {
|
|
1083
|
+
targetMsgId =
|
|
1084
|
+
this.callbackQuery?.message?.message_id ??
|
|
1085
|
+
(this.message && 'message_id' in this.message ? this.message.message_id : undefined) ??
|
|
1086
|
+
(this.update && 'edited_message' in this.update && this.update.edited_message
|
|
1087
|
+
? this.update.edited_message.message_id
|
|
1088
|
+
: undefined) ??
|
|
1089
|
+
this.msgId;
|
|
1090
|
+
content = a;
|
|
1091
|
+
extra = b || {};
|
|
1092
|
+
}
|
|
1093
|
+
const chatId = this.chat?.id ??
|
|
1094
|
+
(this.callbackQuery?.message && 'chat' in this.callbackQuery.message
|
|
1095
|
+
? this.callbackQuery.message.chat.id
|
|
1096
|
+
: undefined);
|
|
1097
|
+
const inlineMsgId = this.inlineMessageId ?? extra?.inline_message_id;
|
|
1098
|
+
if (!inlineMsgId && (!chatId || targetMsgId == null)) {
|
|
1099
|
+
throw new Error('[teledzik] Tidak dapat menemukan chatId atau messageId dari konteks pesan saat ini.');
|
|
1100
|
+
}
|
|
1101
|
+
if (inlineMsgId && !extra.inline_message_id) {
|
|
1102
|
+
extra.inline_message_id = inlineMsgId;
|
|
1103
|
+
}
|
|
1104
|
+
return this.telegram.editRichMessage(chatId, targetMsgId, content, extra);
|
|
1078
1105
|
}
|
|
1079
1106
|
/**
|
|
1080
1107
|
* Enqueue a Telegram API call for the current chat to prevent 429 Too Many Requests errors.
|
|
@@ -1241,9 +1268,7 @@ const Msg = {
|
|
|
1241
1268
|
return 'date' in this && this.date !== 0;
|
|
1242
1269
|
},
|
|
1243
1270
|
has(...keys) {
|
|
1244
|
-
return keys.some((key) =>
|
|
1245
|
-
// @ts-expect-error TS doesn't understand key
|
|
1246
|
-
this[key] != undefined);
|
|
1271
|
+
return keys.some((key) => this[key] != undefined);
|
|
1247
1272
|
},
|
|
1248
1273
|
};
|
|
1249
1274
|
function getMessageFromAnySource(ctx) {
|
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.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.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,11 @@ 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
|
+
var rich_message_1 = require("./core/types/rich-message");
|
|
51
|
+
Object.defineProperty(exports, "RichHTMLBuilder", { enumerable: true, get: function () { return rich_message_1.RichHTMLBuilder; } });
|
|
52
|
+
Object.defineProperty(exports, "RichMarkdownBuilder", { enumerable: true, get: function () { return rich_message_1.RichMarkdownBuilder; } });
|
|
53
|
+
Object.defineProperty(exports, "HTML", { enumerable: true, get: function () { return rich_message_1.RichHTMLBuilder; } });
|
|
54
|
+
Object.defineProperty(exports, "MD", { enumerable: true, get: function () { return rich_message_1.MD; } });
|
|
50
55
|
var smart_queue_1 = require("./core/helpers/smart-queue");
|
|
51
56
|
Object.defineProperty(exports, "SmartQueue", { enumerable: true, get: function () { return smart_queue_1.SmartQueue; } });
|
|
52
57
|
var ai_stream_1 = require("./core/helpers/ai-stream");
|
package/lib/telegram.js
CHANGED
|
@@ -1271,18 +1271,97 @@ class Telegram extends client_1.default {
|
|
|
1271
1271
|
...extra,
|
|
1272
1272
|
});
|
|
1273
1273
|
}
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1274
|
+
async editRichMessage(chatId, messageId, contentOrInline, contentOrExtra, maybeExtra) {
|
|
1275
|
+
let inlineMessageId;
|
|
1276
|
+
let content;
|
|
1277
|
+
let extra = {};
|
|
1278
|
+
if (typeof contentOrInline === 'string' &&
|
|
1279
|
+
(typeof contentOrExtra === 'object' || typeof contentOrExtra === 'string') &&
|
|
1280
|
+
maybeExtra !== undefined) {
|
|
1281
|
+
inlineMessageId = contentOrInline;
|
|
1282
|
+
content = contentOrExtra;
|
|
1283
|
+
extra = maybeExtra || {};
|
|
1284
|
+
}
|
|
1285
|
+
else {
|
|
1286
|
+
content = contentOrInline;
|
|
1287
|
+
extra = contentOrExtra || {};
|
|
1288
|
+
inlineMessageId = extra?.inline_message_id;
|
|
1289
|
+
}
|
|
1290
|
+
let htmlText = '';
|
|
1291
|
+
let replyMarkup = extra?.reply_markup;
|
|
1292
|
+
// 1. Omni-format input extraction
|
|
1293
|
+
if (content && typeof content.build === 'function') {
|
|
1294
|
+
const built = content.build();
|
|
1295
|
+
if (typeof built === 'object' && built !== null) {
|
|
1296
|
+
htmlText = built.html || built.text || built.caption || '';
|
|
1297
|
+
if (built.reply_markup) {
|
|
1298
|
+
replyMarkup = replyMarkup || built.reply_markup;
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
else {
|
|
1302
|
+
htmlText = String(built || '');
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
else if (typeof content === 'object' && content !== null) {
|
|
1306
|
+
htmlText = content.html || content.text || content.caption || content.markdown || '';
|
|
1307
|
+
if (content.reply_markup) {
|
|
1308
|
+
replyMarkup = replyMarkup || content.reply_markup;
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
else if (typeof content === 'string') {
|
|
1312
|
+
htmlText = content;
|
|
1313
|
+
}
|
|
1314
|
+
// Sanitize rich HTML formatting (tables, headers, details, etc.)
|
|
1315
|
+
htmlText = (0, rich_sanitizer_1.sanitizeRichHtml)(htmlText);
|
|
1316
|
+
// 2. Prepare Base Payload
|
|
1317
|
+
const isInline = Boolean(inlineMessageId || extra?.inline_message_id);
|
|
1318
|
+
const basePayload = {
|
|
1319
|
+
parse_mode: 'HTML',
|
|
1284
1320
|
...extra,
|
|
1285
|
-
}
|
|
1321
|
+
};
|
|
1322
|
+
if (isInline) {
|
|
1323
|
+
basePayload.inline_message_id = inlineMessageId || extra.inline_message_id;
|
|
1324
|
+
}
|
|
1325
|
+
else {
|
|
1326
|
+
basePayload.chat_id = chatId;
|
|
1327
|
+
basePayload.message_id = messageId != null ? Number(messageId) : undefined;
|
|
1328
|
+
}
|
|
1329
|
+
if (replyMarkup) {
|
|
1330
|
+
basePayload.reply_markup = replyMarkup;
|
|
1331
|
+
}
|
|
1332
|
+
// 3. Execution with Auto-Detect (Text -> Caption Fallback) and Silent Error Handling
|
|
1333
|
+
try {
|
|
1334
|
+
return await this.callApi('editMessageText', {
|
|
1335
|
+
...basePayload,
|
|
1336
|
+
text: htmlText,
|
|
1337
|
+
});
|
|
1338
|
+
}
|
|
1339
|
+
catch (err) {
|
|
1340
|
+
const desc = String(err?.description || err?.message || '');
|
|
1341
|
+
// Fallback: If target is a Media message (Photo, Video, Audio, Document, Animation)
|
|
1342
|
+
if (desc.includes('no text in the message') ||
|
|
1343
|
+
desc.includes('there is no text in the message to edit') ||
|
|
1344
|
+
desc.includes('message to edit not found')) {
|
|
1345
|
+
try {
|
|
1346
|
+
return await this.callApi('editMessageCaption', {
|
|
1347
|
+
...basePayload,
|
|
1348
|
+
caption: htmlText,
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1351
|
+
catch (captionErr) {
|
|
1352
|
+
const capDesc = String(captionErr?.description || captionErr?.message || '');
|
|
1353
|
+
if (capDesc.includes('message is not modified')) {
|
|
1354
|
+
return false;
|
|
1355
|
+
}
|
|
1356
|
+
throw captionErr;
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
// Gracefully handle 'message is not modified'
|
|
1360
|
+
if (desc.includes('message is not modified')) {
|
|
1361
|
+
return false;
|
|
1362
|
+
}
|
|
1363
|
+
throw err;
|
|
1364
|
+
}
|
|
1286
1365
|
}
|
|
1287
1366
|
}
|
|
1288
1367
|
exports.Telegram = Telegram;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "teledzik",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
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 1.0.
|
|
15
|
+
"bot api 1.0.5"
|
|
16
16
|
],
|
|
17
17
|
"homepage": "https://telegraf.js.org",
|
|
18
18
|
"bugs": {
|
package/src/button.ts
CHANGED
|
@@ -105,20 +105,26 @@ export function channelRequest(
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
export type ButtonStyle = 'primary' | 'success' | 'danger'
|
|
109
|
+
|
|
108
110
|
export function url(
|
|
109
111
|
text: string,
|
|
110
112
|
url: string,
|
|
111
|
-
hide = false
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
hide = false,
|
|
114
|
+
style?: ButtonStyle,
|
|
115
|
+
icon_custom_emoji_id?: string
|
|
116
|
+
): Hideable<InlineKeyboardButton.UrlButton & { style?: ButtonStyle; icon_custom_emoji_id?: string }> {
|
|
117
|
+
return { text, url, hide, ...(style ? { style } : {}), ...(icon_custom_emoji_id ? { icon_custom_emoji_id } : {}) }
|
|
114
118
|
}
|
|
115
119
|
|
|
116
120
|
export function callback(
|
|
117
121
|
text: string,
|
|
118
122
|
data: string,
|
|
119
|
-
hide = false
|
|
120
|
-
|
|
121
|
-
|
|
123
|
+
hide = false,
|
|
124
|
+
style?: ButtonStyle,
|
|
125
|
+
icon_custom_emoji_id?: string
|
|
126
|
+
): Hideable<InlineKeyboardButton.CallbackButton & { style?: ButtonStyle; icon_custom_emoji_id?: string }> {
|
|
127
|
+
return { text, callback_data: data, hide, ...(style ? { style } : {}), ...(icon_custom_emoji_id ? { icon_custom_emoji_id } : {}) }
|
|
122
128
|
}
|
|
123
129
|
|
|
124
130
|
export function switchToChat(
|
|
@@ -180,3 +186,80 @@ export function webApp(
|
|
|
180
186
|
hide,
|
|
181
187
|
}
|
|
182
188
|
}
|
|
189
|
+
|
|
190
|
+
// ââ Native Telegram Background Color Buttons (Bot API 9.4+) âââââââââââââââ
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* đĩ Primary callback button (Blue background)
|
|
194
|
+
*/
|
|
195
|
+
export function primary(
|
|
196
|
+
text: string,
|
|
197
|
+
data: string,
|
|
198
|
+
hide = false,
|
|
199
|
+
icon_custom_emoji_id?: string
|
|
200
|
+
) {
|
|
201
|
+
return callback(text, data, hide, 'primary', icon_custom_emoji_id)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* đĸ Success callback button (Green background)
|
|
206
|
+
*/
|
|
207
|
+
export function success(
|
|
208
|
+
text: string,
|
|
209
|
+
data: string,
|
|
210
|
+
hide = false,
|
|
211
|
+
icon_custom_emoji_id?: string
|
|
212
|
+
) {
|
|
213
|
+
return callback(text, data, hide, 'success', icon_custom_emoji_id)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* đ´ Danger / Delete callback button (Red background)
|
|
218
|
+
*/
|
|
219
|
+
export function danger(
|
|
220
|
+
text: string,
|
|
221
|
+
data: string,
|
|
222
|
+
hide = false,
|
|
223
|
+
icon_custom_emoji_id?: string
|
|
224
|
+
) {
|
|
225
|
+
return callback(text, data, hide, 'danger', icon_custom_emoji_id)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* đĩ Primary URL button (Blue background)
|
|
230
|
+
*/
|
|
231
|
+
export function primaryUrl(
|
|
232
|
+
text: string,
|
|
233
|
+
targetUrl: string,
|
|
234
|
+
hide = false,
|
|
235
|
+
icon_custom_emoji_id?: string
|
|
236
|
+
) {
|
|
237
|
+
return url(text, targetUrl, hide, 'primary', icon_custom_emoji_id)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* đĸ Success URL button (Green background)
|
|
242
|
+
*/
|
|
243
|
+
export function successUrl(
|
|
244
|
+
text: string,
|
|
245
|
+
targetUrl: string,
|
|
246
|
+
hide = false,
|
|
247
|
+
icon_custom_emoji_id?: string
|
|
248
|
+
) {
|
|
249
|
+
return url(text, targetUrl, hide, 'success', icon_custom_emoji_id)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* đ´ Danger URL button (Red background)
|
|
254
|
+
*/
|
|
255
|
+
export function dangerUrl(
|
|
256
|
+
text: string,
|
|
257
|
+
targetUrl: string,
|
|
258
|
+
hide = false,
|
|
259
|
+
icon_custom_emoji_id?: string
|
|
260
|
+
) {
|
|
261
|
+
return url(text, targetUrl, hide, 'danger', icon_custom_emoji_id)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
package/src/context.ts
CHANGED
|
@@ -1407,17 +1407,61 @@ export class Context<U extends Deunionize<tg.Update> = tg.Update> {
|
|
|
1407
1407
|
}
|
|
1408
1408
|
|
|
1409
1409
|
/**
|
|
1410
|
-
*
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1410
|
+
* Universal Context shortcut to edit message with Omni-Format support (RichHTMLBuilder, Object, or String),
|
|
1411
|
+
* auto-detection of Text vs Media Caption, and silent 'not modified' error handling.
|
|
1412
|
+
*/
|
|
1413
|
+
editRichMessage(
|
|
1414
|
+
content: tg.RichContentInput,
|
|
1415
|
+
extra?: tg.EditRichOptions
|
|
1416
|
+
): Promise<any>
|
|
1417
|
+
editRichMessage(
|
|
1418
|
+
messageId: number | string,
|
|
1419
|
+
content: tg.RichContentInput,
|
|
1420
|
+
extra?: tg.EditRichOptions
|
|
1421
|
+
): Promise<any>
|
|
1422
|
+
async editRichMessage(a: any, b?: any, c?: any): Promise<any> {
|
|
1423
|
+
let targetMsgId: number | string | undefined
|
|
1424
|
+
let content: any
|
|
1425
|
+
let extra: any = {}
|
|
1426
|
+
|
|
1427
|
+
if (
|
|
1428
|
+
typeof a === 'number' ||
|
|
1429
|
+
(typeof a === 'string' && !isNaN(Number(a)) && b !== undefined)
|
|
1430
|
+
) {
|
|
1431
|
+
targetMsgId = a
|
|
1432
|
+
content = b
|
|
1433
|
+
extra = c || {}
|
|
1434
|
+
} else {
|
|
1435
|
+
targetMsgId =
|
|
1436
|
+
this.callbackQuery?.message?.message_id ??
|
|
1437
|
+
(this.message && 'message_id' in this.message ? this.message.message_id : undefined) ??
|
|
1438
|
+
(this.update && 'edited_message' in this.update && this.update.edited_message
|
|
1439
|
+
? this.update.edited_message.message_id
|
|
1440
|
+
: undefined) ??
|
|
1441
|
+
this.msgId
|
|
1442
|
+
content = a
|
|
1443
|
+
extra = b || {}
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
const chatId =
|
|
1447
|
+
this.chat?.id ??
|
|
1448
|
+
(this.callbackQuery?.message && 'chat' in this.callbackQuery.message
|
|
1449
|
+
? this.callbackQuery.message.chat.id
|
|
1450
|
+
: undefined)
|
|
1451
|
+
|
|
1452
|
+
const inlineMsgId = this.inlineMessageId ?? extra?.inline_message_id
|
|
1453
|
+
|
|
1454
|
+
if (!inlineMsgId && (!chatId || targetMsgId == null)) {
|
|
1455
|
+
throw new Error(
|
|
1456
|
+
'[teledzik] Tidak dapat menemukan chatId atau messageId dari konteks pesan saat ini.'
|
|
1457
|
+
)
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
if (inlineMsgId && !extra.inline_message_id) {
|
|
1461
|
+
extra.inline_message_id = inlineMsgId
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
return this.telegram.editRichMessage(chatId, targetMsgId, content, extra)
|
|
1421
1465
|
}
|
|
1422
1466
|
|
|
1423
1467
|
/**
|
|
@@ -1650,18 +1694,14 @@ interface Msg {
|
|
|
1650
1694
|
): this is MaybeMessage<Keyed<tg.Message, Ks[number]>>
|
|
1651
1695
|
}
|
|
1652
1696
|
|
|
1653
|
-
const Msg
|
|
1654
|
-
isAccessible() {
|
|
1697
|
+
const Msg = {
|
|
1698
|
+
isAccessible(this: any) {
|
|
1655
1699
|
return 'date' in this && this.date !== 0
|
|
1656
1700
|
},
|
|
1657
|
-
has(...keys) {
|
|
1658
|
-
return keys.some(
|
|
1659
|
-
(key) =>
|
|
1660
|
-
// @ts-expect-error TS doesn't understand key
|
|
1661
|
-
this[key] != undefined
|
|
1662
|
-
)
|
|
1701
|
+
has(this: any, ...keys: string[]) {
|
|
1702
|
+
return keys.some((key) => this[key] != undefined)
|
|
1663
1703
|
},
|
|
1664
|
-
}
|
|
1704
|
+
} as Msg
|
|
1665
1705
|
|
|
1666
1706
|
export type MaybeMessage<
|
|
1667
1707
|
M extends tg.MaybeInaccessibleMessage = tg.MaybeInaccessibleMessage,
|
|
@@ -32,6 +32,21 @@ export interface InputRichMessageContent {
|
|
|
32
32
|
rich_message: InputRichMessage
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
export interface EditRichOptions {
|
|
36
|
+
reply_markup?: any
|
|
37
|
+
disable_web_page_preview?: boolean
|
|
38
|
+
link_preview_options?: any
|
|
39
|
+
inline_message_id?: string
|
|
40
|
+
[key: string]: any
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type RichContentInput =
|
|
44
|
+
| string
|
|
45
|
+
| { html?: string; text?: string; caption?: string; markdown?: string; reply_markup?: any }
|
|
46
|
+
| { build(): string | InputRichMessage | { html?: string; text?: string; reply_markup?: any } }
|
|
47
|
+
| InputRichMessage
|
|
48
|
+
|
|
49
|
+
|
|
35
50
|
// ---------------------------------------------------------------------------
|
|
36
51
|
// HTML Builder
|
|
37
52
|
// ---------------------------------------------------------------------------
|
package/src/index.ts
CHANGED
|
@@ -16,6 +16,7 @@ export { session, MemorySessionStore, SessionStore } from './session'
|
|
|
16
16
|
|
|
17
17
|
export * as Scenes from './scenes'
|
|
18
18
|
export * as RichMessage from './core/types/rich-message'
|
|
19
|
+
export { RichHTMLBuilder, RichMarkdownBuilder, RichHTMLBuilder as HTML, MD } from './core/types/rich-message'
|
|
19
20
|
|
|
20
21
|
export { SmartQueue } from './core/helpers/smart-queue'
|
|
21
22
|
export { AIStreamAdapter } from './core/helpers/ai-stream'
|