Skip to content

Commit e1e7971

Browse files
committed
feat: Bot API 7.0
1 parent b74e2cf commit e1e7971

File tree

7 files changed

+94
-0
lines changed

7 files changed

+94
-0
lines changed

source/html.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,34 @@ test("underline", () => {
2121
strictEqual(format.underline("underline"), "<u>underline</u>");
2222
});
2323

24+
test("blockquote", () => {
25+
strictEqual(
26+
format.blockquote("blockquote"),
27+
"<blockquote>blockquote</blockquote>",
28+
);
29+
});
30+
31+
test("blockquote multiline", () => {
32+
strictEqual(
33+
format.blockquote("blockquote\nmultiline"),
34+
"<blockquote>blockquote\nmultiline</blockquote>",
35+
);
36+
});
37+
2438
test("spoiler", () => {
2539
strictEqual(
2640
format.spoiler("spoiler"),
2741
'<span class="tg-spoiler">spoiler</span>',
2842
);
2943
});
3044

45+
test("tgEmoji", () => {
46+
strictEqual(
47+
format.tgEmoji("👍", "5368324170671202286"),
48+
'<tg-emoji emoji-id="5368324170671202286">👍</tg-emoji>',
49+
);
50+
});
51+
3152
test("url", () => {
3253
strictEqual(
3354
format.url("me", "https://edjopato.de"),

source/html.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,25 @@ export function underline(text: string): string {
2929
return `<u>${text}</u>`;
3030
}
3131

32+
/** Format the input text as blockquote */
33+
export function blockquote(text: string): string {
34+
return `<blockquote>${text}</blockquote>`;
35+
}
36+
3237
/** Format the input text as spoiler */
3338
export function spoiler(text: string): string {
3439
return `<span class="tg-spoiler">${text}</span>`;
3540
}
3641

42+
/** Create a custom Telegram Emoji.
43+
*
44+
* A valid emoji must be used as the fallback. The emoji will be shown instead of the custom emoji in places where a custom emoji cannot be displayed (e.g., system notifications) or if the message is forwarded by a non-premium user. It is recommended to use the emoji from the emoji field of the custom emoji sticker.
45+
* Custom emoji entities can only be used by bots that purchased additional usernames on Fragment.
46+
*/
47+
export function tgEmoji(fallback: string, emojiId: string): string {
48+
return `<tg-emoji emoji-id="${emojiId}">${fallback}</tg-emoji>`;
49+
}
50+
3751
/** Format the input text as monospace */
3852
export function monospace(text: string): string {
3953
return `<code>${escape(text)}</code>`;

source/markdown.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ test("underline", () => {
7171
throws(() => format.underline("1337"));
7272
});
7373

74+
test("blockquote", () => {
75+
throws(() => format.blockquote("1337"));
76+
});
77+
7478
test("spoiler", () => {
7579
throws(() => format.spoiler("1337"));
7680
});
81+
82+
test("tgEmoji", () => {
83+
throws(() => format.tgEmoji("👍", "5368324170671202286"));
84+
});

source/markdown.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,27 @@ export function underline(_text: string): string {
3030
);
3131
}
3232

33+
/** unsupported by Telegram. Use MarkdownV2 or HTML instead @deprecated */
34+
export function blockquote(_text: string): string {
35+
throw new Error(
36+
"blockquote is not supported by Markdown. Use MarkdownV2 instead.",
37+
);
38+
}
39+
3340
/** unsupported by Telegram. Use MarkdownV2 or HTML instead @deprecated */
3441
export function spoiler(_text: string): string {
3542
throw new Error(
3643
"spoiler is not supported by Markdown. Use MarkdownV2 instead.",
3744
);
3845
}
3946

47+
/** unsupported by Telegram. Use MarkdownV2 or HTML instead @deprecated */
48+
export function tgEmoji(_fallback: string, _emojiId: string): string {
49+
throw new Error(
50+
"tgEmoji is not supported by Markdown. Use MarkdownV2 instead.",
51+
);
52+
}
53+
4054
/** Format the input text as monospace */
4155
export function monospace(text: string): string {
4256
return "`" + text.replace(/`/g, "") + "`";

source/markdownv2.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,28 @@ test("underline", () => {
2121
strictEqual(format.underline("underline"), "__underline__");
2222
});
2323

24+
test("blockquote", () => {
25+
strictEqual(format.blockquote("blockquote"), ">blockquote");
26+
});
27+
28+
test("blockquote multiline", () => {
29+
strictEqual(
30+
format.blockquote("blockquote\nmultiline"),
31+
">blockquote\n>multiline",
32+
);
33+
});
34+
2435
test("spoiler", () => {
2536
strictEqual(format.spoiler("spoiler"), "||spoiler||");
2637
});
2738

39+
test("tgEmoji", () => {
40+
strictEqual(
41+
format.tgEmoji("👍", "5368324170671202286"),
42+
"![👍](tg://emoji?id=5368324170671202286)",
43+
);
44+
});
45+
2846
test("url", () => {
2947
strictEqual(
3048
format.url("me", "https://edjopato.de"),

source/markdownv2.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,26 @@ export function underline(text: string): string {
3030
return `__${text}__`;
3131
}
3232

33+
/** Format the input text as blockquote */
34+
export function blockquote(text: string): string {
35+
const lines = text.split("\n");
36+
return lines.map((o) => ">" + o).join("\n");
37+
}
38+
3339
/** Format the input text as spoiler */
3440
export function spoiler(text: string): string {
3541
return `||${text}||`;
3642
}
3743

44+
/** Create a custom Telegram Emoji.
45+
*
46+
* A valid emoji must be used as the fallback. The emoji will be shown instead of the custom emoji in places where a custom emoji cannot be displayed (e.g., system notifications) or if the message is forwarded by a non-premium user. It is recommended to use the emoji from the emoji field of the custom emoji sticker.
47+
* Custom emoji entities can only be used by bots that purchased additional usernames on Fragment.
48+
*/
49+
export function tgEmoji(fallback: string, emojiId: string): string {
50+
return `![${fallback}](tg://emoji?id=${emojiId})`;
51+
}
52+
3853
/** Format the input text as monospace */
3954
export function monospace(text: string): string {
4055
return "`" + escapeInternal(text, "`") + "`";

source/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
export interface Formatter {
33
/** parse_mode which can be used on sendMessage */
44
parse_mode: "HTML" | "Markdown" | "MarkdownV2";
5+
/** Format the input text as blockquote */
6+
blockquote: (text: string) => string;
57
/** Format the input text bold */
68
bold: (text: string) => string;
79
/** Escape the input text to be displayed as it is */
@@ -16,6 +18,8 @@ export interface Formatter {
1618
spoiler: (text: string) => string;
1719
/** Strikethrough the input text */
1820
strikethrough: (text: string) => string;
21+
/** Create a custom Telegram Emoji */
22+
tgEmoji: (fallback: string, emojiId: string) => string;
1923
/** Underline the input text */
2024
underline: (text: string) => string;
2125
/** Create an url with a label text */

0 commit comments

Comments
 (0)