teledzik 1.0.4 → 1.0.6
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 +26 -0
- package/lib/context.js +13 -6
- package/lib/index.js +6 -1
- package/lib/telegram.js +18 -8
- package/package.json +2 -2
- package/src/context.ts +21 -20
- package/src/core/types/rich-message.ts +15 -0
- package/src/index.ts +1 -0
- package/src/telegram.ts +22 -14
- package/typings/context.d.ts +2 -2
- package/typings/core/types/rich-message.d.ts +20 -0
- package/typings/index.d.ts +1 -0
- package/typings/telegram.d.ts +3 -2
package/README.md
CHANGED
|
@@ -588,6 +588,32 @@ await ctx.sendRichMessage(msg, {
|
|
|
588
588
|
|
|
589
589
|
---
|
|
590
590
|
|
|
591
|
+
### Native `editRichMessage` (Preserving 100% Rich UI)
|
|
592
|
+
|
|
593
|
+
Edit a rich message in-place while preserving 100% Native Rich UI layout (tables, headings, cards, collapsibles):
|
|
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
|
+
// Edit in-place with native Rich UI preservation
|
|
609
|
+
await ctx.editRichMessage(rich, {
|
|
610
|
+
reply_markup: Markup.inlineKeyboard([
|
|
611
|
+
[Markup.button.primary('🔄 Refresh', 'btn:update')]
|
|
612
|
+
]).reply_markup
|
|
613
|
+
})
|
|
614
|
+
})
|
|
615
|
+
```
|
|
616
|
+
|
|
591
617
|
### Inline / Web App Queries
|
|
592
618
|
|
|
593
619
|
Use `InputRichMessageContent` as `input_message_content` in inline query results:
|
package/lib/context.js
CHANGED
|
@@ -1070,11 +1070,20 @@ class Context {
|
|
|
1070
1070
|
return this.telegram.sendRichMessageDraft(this.chat.id, draftId, richMessage, extra);
|
|
1071
1071
|
}
|
|
1072
1072
|
/**
|
|
1073
|
-
*
|
|
1073
|
+
* Context-aware shorthand for {@link Telegram.editRichMessage}.
|
|
1074
1074
|
*/
|
|
1075
1075
|
editRichMessage(richMessage, extra) {
|
|
1076
|
-
this.assert(this.
|
|
1077
|
-
|
|
1076
|
+
this.assert(this.chat, 'editRichMessage');
|
|
1077
|
+
const messageId = this.callbackQuery?.message?.message_id ||
|
|
1078
|
+
(this.message && 'message_id' in this.message ? this.message.message_id : undefined) ||
|
|
1079
|
+
(this.update && 'edited_message' in this.update && this.update.edited_message
|
|
1080
|
+
? this.update.edited_message.message_id
|
|
1081
|
+
: undefined) ||
|
|
1082
|
+
this.msgId;
|
|
1083
|
+
if (!messageId) {
|
|
1084
|
+
throw new Error('[teledzik] Tidak dapat menemukan message_id untuk diedit.');
|
|
1085
|
+
}
|
|
1086
|
+
return this.telegram.editRichMessage(this.chat.id, messageId, richMessage, extra);
|
|
1078
1087
|
}
|
|
1079
1088
|
/**
|
|
1080
1089
|
* Enqueue a Telegram API call for the current chat to prevent 429 Too Many Requests errors.
|
|
@@ -1241,9 +1250,7 @@ const Msg = {
|
|
|
1241
1250
|
return 'date' in this && this.date !== 0;
|
|
1242
1251
|
},
|
|
1243
1252
|
has(...keys) {
|
|
1244
|
-
return keys.some((key) =>
|
|
1245
|
-
// @ts-expect-error TS doesn't understand key
|
|
1246
|
-
this[key] != undefined);
|
|
1253
|
+
return keys.some((key) => this[key] != undefined);
|
|
1247
1254
|
},
|
|
1248
1255
|
};
|
|
1249
1256
|
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
|
@@ -1272,17 +1272,27 @@ class Telegram extends client_1.default {
|
|
|
1272
1272
|
});
|
|
1273
1273
|
}
|
|
1274
1274
|
/**
|
|
1275
|
-
* Edit a
|
|
1275
|
+
* Edit a rich message in-place while preserving 100% Native Rich UI layout (tables, headings, cards).
|
|
1276
|
+
* @see https://core.telegram.org/bots/api#editrichmessage
|
|
1276
1277
|
*/
|
|
1277
|
-
editRichMessage(chatId, messageId,
|
|
1278
|
-
|
|
1278
|
+
async editRichMessage(chatId, messageId, richMessage, extra) {
|
|
1279
|
+
const payload = {
|
|
1279
1280
|
chat_id: chatId,
|
|
1280
|
-
message_id: messageId,
|
|
1281
|
-
|
|
1282
|
-
text: richMessage.html ?? richMessage.markdown ?? '',
|
|
1283
|
-
parse_mode: richMessage.html ? 'HTML' : richMessage.markdown ? 'MarkdownV2' : undefined,
|
|
1281
|
+
message_id: Number(messageId),
|
|
1282
|
+
rich_message: typeof richMessage?.build === 'function' ? richMessage.build() : richMessage,
|
|
1284
1283
|
...extra,
|
|
1285
|
-
}
|
|
1284
|
+
};
|
|
1285
|
+
try {
|
|
1286
|
+
return await this.callApi('editRichMessage', payload);
|
|
1287
|
+
}
|
|
1288
|
+
catch (err) {
|
|
1289
|
+
const desc = String(err?.description || err?.message || '');
|
|
1290
|
+
// Silent ignore jika konten pesan tidak mengalami perubahan
|
|
1291
|
+
if (desc.includes('message is not modified')) {
|
|
1292
|
+
return false;
|
|
1293
|
+
}
|
|
1294
|
+
throw err;
|
|
1295
|
+
}
|
|
1286
1296
|
}
|
|
1287
1297
|
}
|
|
1288
1298
|
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.6",
|
|
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/context.ts
CHANGED
|
@@ -1407,17 +1407,22 @@ export class Context<U extends Deunionize<tg.Update> = tg.Update> {
|
|
|
1407
1407
|
}
|
|
1408
1408
|
|
|
1409
1409
|
/**
|
|
1410
|
-
*
|
|
1411
|
-
*/
|
|
1412
|
-
editRichMessage(richMessage:
|
|
1413
|
-
this.assert(this.
|
|
1414
|
-
|
|
1415
|
-
this.
|
|
1416
|
-
this.
|
|
1417
|
-
this.
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1410
|
+
* Context-aware shorthand for {@link Telegram.editRichMessage}.
|
|
1411
|
+
*/
|
|
1412
|
+
editRichMessage(richMessage: any, extra?: any): Promise<any> {
|
|
1413
|
+
this.assert(this.chat, 'editRichMessage')
|
|
1414
|
+
const messageId =
|
|
1415
|
+
this.callbackQuery?.message?.message_id ||
|
|
1416
|
+
(this.message && 'message_id' in this.message ? this.message.message_id : undefined) ||
|
|
1417
|
+
(this.update && 'edited_message' in this.update && this.update.edited_message
|
|
1418
|
+
? this.update.edited_message.message_id
|
|
1419
|
+
: undefined) ||
|
|
1420
|
+
this.msgId
|
|
1421
|
+
|
|
1422
|
+
if (!messageId) {
|
|
1423
|
+
throw new Error('[teledzik] Tidak dapat menemukan message_id untuk diedit.')
|
|
1424
|
+
}
|
|
1425
|
+
return this.telegram.editRichMessage(this.chat.id, messageId, richMessage, extra)
|
|
1421
1426
|
}
|
|
1422
1427
|
|
|
1423
1428
|
/**
|
|
@@ -1650,18 +1655,14 @@ interface Msg {
|
|
|
1650
1655
|
): this is MaybeMessage<Keyed<tg.Message, Ks[number]>>
|
|
1651
1656
|
}
|
|
1652
1657
|
|
|
1653
|
-
const Msg
|
|
1654
|
-
isAccessible() {
|
|
1658
|
+
const Msg = {
|
|
1659
|
+
isAccessible(this: any) {
|
|
1655
1660
|
return 'date' in this && this.date !== 0
|
|
1656
1661
|
},
|
|
1657
|
-
has(...keys) {
|
|
1658
|
-
return keys.some(
|
|
1659
|
-
(key) =>
|
|
1660
|
-
// @ts-expect-error TS doesn't understand key
|
|
1661
|
-
this[key] != undefined
|
|
1662
|
-
)
|
|
1662
|
+
has(this: any, ...keys: string[]) {
|
|
1663
|
+
return keys.some((key) => this[key] != undefined)
|
|
1663
1664
|
},
|
|
1664
|
-
}
|
|
1665
|
+
} as Msg
|
|
1665
1666
|
|
|
1666
1667
|
export type MaybeMessage<
|
|
1667
1668
|
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'
|
package/src/telegram.ts
CHANGED
|
@@ -1680,23 +1680,31 @@ export class Telegram extends ApiClient {
|
|
|
1680
1680
|
}
|
|
1681
1681
|
|
|
1682
1682
|
/**
|
|
1683
|
-
* Edit a
|
|
1683
|
+
* Edit a rich message in-place while preserving 100% Native Rich UI layout (tables, headings, cards).
|
|
1684
|
+
* @see https://core.telegram.org/bots/api#editrichmessage
|
|
1684
1685
|
*/
|
|
1685
|
-
editRichMessage(
|
|
1686
|
-
chatId: number | string
|
|
1687
|
-
messageId: number |
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
return this.callApi('editMessageText' as never, {
|
|
1686
|
+
async editRichMessage(
|
|
1687
|
+
chatId: number | string,
|
|
1688
|
+
messageId: number | string,
|
|
1689
|
+
richMessage: any,
|
|
1690
|
+
extra?: any
|
|
1691
|
+
): Promise<any> {
|
|
1692
|
+
const payload: Record<string, any> = {
|
|
1693
1693
|
chat_id: chatId,
|
|
1694
|
-
message_id: messageId,
|
|
1695
|
-
|
|
1696
|
-
text: richMessage.html ?? richMessage.markdown ?? '',
|
|
1697
|
-
parse_mode: richMessage.html ? 'HTML' : richMessage.markdown ? 'MarkdownV2' : undefined,
|
|
1694
|
+
message_id: Number(messageId),
|
|
1695
|
+
rich_message: typeof richMessage?.build === 'function' ? richMessage.build() : richMessage,
|
|
1698
1696
|
...extra,
|
|
1699
|
-
}
|
|
1697
|
+
}
|
|
1698
|
+
try {
|
|
1699
|
+
return await this.callApi('editRichMessage' as never, payload as never)
|
|
1700
|
+
} catch (err: any) {
|
|
1701
|
+
const desc = String(err?.description || err?.message || '')
|
|
1702
|
+
// Silent ignore jika konten pesan tidak mengalami perubahan
|
|
1703
|
+
if (desc.includes('message is not modified')) {
|
|
1704
|
+
return false
|
|
1705
|
+
}
|
|
1706
|
+
throw err
|
|
1707
|
+
}
|
|
1700
1708
|
}
|
|
1701
1709
|
}
|
|
1702
1710
|
|
package/typings/context.d.ts
CHANGED
|
@@ -591,9 +591,9 @@ export declare class Context<U extends Deunionize<tg.Update> = tg.Update> {
|
|
|
591
591
|
*/
|
|
592
592
|
sendRichMessageDraft(draftId: number, richMessage: tg.InputRichMessage, extra?: tt.ExtraSendRichMessageDraft): Promise<never>;
|
|
593
593
|
/**
|
|
594
|
-
*
|
|
594
|
+
* Context-aware shorthand for {@link Telegram.editRichMessage}.
|
|
595
595
|
*/
|
|
596
|
-
editRichMessage(richMessage:
|
|
596
|
+
editRichMessage(richMessage: any, extra?: any): Promise<any>;
|
|
597
597
|
/**
|
|
598
598
|
* Enqueue a Telegram API call for the current chat to prevent 429 Too Many Requests errors.
|
|
599
599
|
*/
|
|
@@ -24,6 +24,26 @@ export interface InputRichMessage {
|
|
|
24
24
|
export interface InputRichMessageContent {
|
|
25
25
|
rich_message: InputRichMessage;
|
|
26
26
|
}
|
|
27
|
+
export interface EditRichOptions {
|
|
28
|
+
reply_markup?: any;
|
|
29
|
+
disable_web_page_preview?: boolean;
|
|
30
|
+
link_preview_options?: any;
|
|
31
|
+
inline_message_id?: string;
|
|
32
|
+
[key: string]: any;
|
|
33
|
+
}
|
|
34
|
+
export type RichContentInput = string | {
|
|
35
|
+
html?: string;
|
|
36
|
+
text?: string;
|
|
37
|
+
caption?: string;
|
|
38
|
+
markdown?: string;
|
|
39
|
+
reply_markup?: any;
|
|
40
|
+
} | {
|
|
41
|
+
build(): string | InputRichMessage | {
|
|
42
|
+
html?: string;
|
|
43
|
+
text?: string;
|
|
44
|
+
reply_markup?: any;
|
|
45
|
+
};
|
|
46
|
+
} | InputRichMessage;
|
|
27
47
|
/**
|
|
28
48
|
* Fluent builder for Rich Messages using HTML format.
|
|
29
49
|
*
|
package/typings/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export { deunionize } from './core/helpers/deunionize';
|
|
|
13
13
|
export { session, MemorySessionStore, SessionStore } from './session';
|
|
14
14
|
export * as Scenes from './scenes';
|
|
15
15
|
export * as RichMessage from './core/types/rich-message';
|
|
16
|
+
export { RichHTMLBuilder, RichMarkdownBuilder, RichHTMLBuilder as HTML, MD } from './core/types/rich-message';
|
|
16
17
|
export { SmartQueue } from './core/helpers/smart-queue';
|
|
17
18
|
export { AIStreamAdapter } from './core/helpers/ai-stream';
|
|
18
19
|
export { sanitizeRichHtml } from './core/helpers/rich-sanitizer';
|
package/typings/telegram.d.ts
CHANGED
|
@@ -690,8 +690,9 @@ export declare class Telegram extends ApiClient {
|
|
|
690
690
|
*/
|
|
691
691
|
sendRichMessageDraft(chatId: number, draftId: number, richMessage: tg.InputRichMessage, extra?: tt.ExtraSendRichMessageDraft): Promise<never>;
|
|
692
692
|
/**
|
|
693
|
-
* Edit a
|
|
693
|
+
* Edit a rich message in-place while preserving 100% Native Rich UI layout (tables, headings, cards).
|
|
694
|
+
* @see https://core.telegram.org/bots/api#editrichmessage
|
|
694
695
|
*/
|
|
695
|
-
editRichMessage(chatId: number | string
|
|
696
|
+
editRichMessage(chatId: number | string, messageId: number | string, richMessage: any, extra?: any): Promise<any>;
|
|
696
697
|
}
|
|
697
698
|
export default Telegram;
|