Skip to content

Commit 31c92f6

Browse files
committed
Add more Walkthrough sections
1 parent 4d0b176 commit 31c92f6

10 files changed

Lines changed: 306 additions & 3 deletions

src/account-auto-deletion.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Account Auto-Deletion
3+
parent: /#walkthrough
4+
walkthrough:
5+
track: user
6+
order: 14
7+
---
8+
9+
User clients can control when an inactive account is automatically deleted.
10+
11+
## Getting the Auto-Deletion Period
12+
13+
Use {{ "getAccountTtl" |> m }} to get the period in days.
14+
15+
```ts
16+
const dayCount = await client.getAccountTtl();
17+
18+
console.log(dayCount);
19+
```
20+
21+
## Setting the Auto-Deletion Period
22+
23+
Use {{ "setAccountTtl" |> m }} with the period in days.
24+
25+
```ts
26+
await client.setAccountTtl(365);
27+
```

src/bot-commands.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ This only changes the displayed command list. Register handlers separately with
2323

2424
## Scoping and Localizing Commands
2525

26-
Pass a `scope` to show a command list only in specific chats. This example sets a command for group administrators.
26+
Pass a `scope` to show a command list only to specific audiences or in specific chats. This example sets a command for group administrators.
2727

2828
```ts
2929
await client.setMyCommands(
@@ -36,8 +36,8 @@ Pass `languageCode` to set a localized command list.
3636

3737
```ts
3838
await client.setMyCommands(
39-
[{ command: "help", description: "Hilfe anzeigen" }],
40-
{ languageCode: "de" },
39+
[{ command: "help", description: "Показать справку" }],
40+
{ languageCode: "ru" },
4141
);
4242
```
4343

src/bot-write-access.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
title: Bot Write Access
3+
parent: /#walkthrough
4+
walkthrough:
5+
track: bot
6+
order: 16
7+
---
8+
9+
Bots can detect when a user allows them to send messages.
10+
11+
## Handling Write Access
12+
13+
Handle `message:writeAccessAllowed` to receive the service message.
14+
15+
```ts
16+
client.on("message:writeAccessAllowed", (ctx) => {
17+
const { miniAppName } = ctx.msg.writeAccessAllowed;
18+
19+
console.log(
20+
miniAppName ? `Write access granted through ${miniAppName}` : "Write access granted",
21+
);
22+
});
23+
```
24+
25+
`miniAppName` is present when access was granted through a Mini App.

src/channel-direct-messages.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: Channel Direct Messages
3+
parent: /#walkthrough
4+
walkthrough:
5+
track: main
6+
order: 19
7+
---
8+
9+
Bots can reply to messages sent through a channel's direct messages.
10+
11+
## Replying to a Direct Message
12+
13+
Incoming direct messages have a `directMessagesTopicId`. Context reply methods reuse it automatically.
14+
15+
```ts
16+
client.on("message", async (ctx) => {
17+
if (ctx.msg.directMessagesTopicId === undefined) {
18+
return;
19+
}
20+
21+
await ctx.reply("Thanks for contacting us.");
22+
});
23+
```
24+
25+
When sending outside an update handler, pass the topic ID explicitly.
26+
27+
```ts
28+
await client.sendMessage(chatId, "Thanks for contacting us.", {
29+
directMessagesTopicId,
30+
});
31+
```

src/login-buttons.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: Login Buttons
3+
parent: /#walkthrough
4+
walkthrough:
5+
track: bot
6+
order: 15
7+
---
8+
9+
Bots can let users sign in to a website with their Telegram account.
10+
11+
## Sending a Login Button
12+
13+
Link the website's domain to the bot through [@BotFather](https://t.me/BotFather), then send a `loginUrl` button with an HTTPS URL.
14+
15+
```ts
16+
client.command("login", async (ctx) => {
17+
await ctx.reply("Sign in to continue:", {
18+
replyMarkup: {
19+
type: "inlineKeyboard",
20+
inlineKeyboard: [
21+
[
22+
{
23+
type: "loginUrl",
24+
text: "Sign in",
25+
loginUrl: {
26+
url: "https://example.com/login",
27+
},
28+
},
29+
],
30+
],
31+
},
32+
});
33+
});
34+
```
35+
36+
Telegram adds signed authentication data to the URL. Verify it on the server before signing the user in.

src/message-translation.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: Message Translation
3+
parent: /#walkthrough
4+
walkthrough:
5+
track: user
6+
order: 12
7+
---
8+
9+
User clients can translate messages and text into another language.
10+
11+
## Translating a Message
12+
13+
Use {{ "translateMessage" |> m }} with the target language code, chat identifier, and message identifier.
14+
15+
```ts
16+
const translation = await client.translateMessage("en", chatId, messageId);
17+
18+
console.log(translation.text);
19+
```
20+
21+
Use {{ "translateMessages" |> m }} to translate multiple messages at once.
22+
23+
## Translating Text
24+
25+
Use {{ "translateText" |> m }} with the target language code and a {{ "TextToTranslate" |> t }}.
26+
27+
```ts
28+
const translation = await client.translateText("en", {
29+
text: "Hola",
30+
entities: [],
31+
});
32+
33+
console.log(translation.text);
34+
```
35+
36+
Use {{ "translateTexts" |> m }} to translate multiple texts at once.

src/paid-media.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Paid Media
3+
parent: /#walkthrough
4+
walkthrough:
5+
track: main
6+
order: 20
7+
---
8+
9+
Bots can require users to pay Telegram Stars before viewing a photo or video.
10+
11+
## Sending Paid Media
12+
13+
Pass `starCount` to {{ "sendPhoto" |> m }} or {{ "sendVideo" |> m }} to set the number of Stars required to unlock the media.
14+
15+
```ts
16+
await client.sendPhoto(chatId, "./photo.jpg", {
17+
starCount: 25,
18+
});
19+
```

src/premium-subscription-gifts.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
title: Premium Subscription Gifts
3+
parent: /#walkthrough
4+
walkthrough:
5+
track: bot
6+
order: 13
7+
---
8+
9+
Bots can gift Telegram Premium subscriptions to users with Telegram Stars.
10+
11+
## Gifting a Subscription
12+
13+
Use {{ "giftPremiumSubscription" |> m }} with the user's identifier and a duration of 3, 6, or 12 months.
14+
15+
```ts
16+
await client.giftPremiumSubscription(userId, 3);
17+
```
18+
19+
Pass `text` to attach a message to the gift.
20+
21+
```ts
22+
await client.giftPremiumSubscription(userId, 12, {
23+
text: "Thanks for being part of the community!",
24+
});
25+
```

src/requesting-users.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
title: Requesting Users
3+
parent: /#walkthrough
4+
walkthrough:
5+
track: bot
6+
order: 14
7+
---
8+
9+
Bots can ask users to select a user through Telegram's user picker.
10+
11+
## Requesting a User
12+
13+
Send a `requestUser` button in a custom keyboard. The `requestId` identifies the request when the user responds.
14+
15+
```ts
16+
client.command("choose_user", async (ctx) => {
17+
await ctx.reply("Choose a user:", {
18+
replyMarkup: {
19+
type: "keyboard",
20+
keyboard: [
21+
[
22+
{
23+
type: "requestUser",
24+
text: "Choose a user",
25+
requestId: 1,
26+
},
27+
],
28+
],
29+
isOneTime: true,
30+
isResized: true,
31+
},
32+
});
33+
});
34+
```
35+
36+
## Handling the Selection
37+
38+
The bot receives a `userShared` message containing the request ID and selected user ID.
39+
40+
```ts
41+
client.on("message:userShared", (ctx) => {
42+
const { requestId, userId } = ctx.msg.userShared;
43+
console.log(requestId, userId);
44+
});
45+
```

src/usernames.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: Usernames
3+
parent: /#walkthrough
4+
walkthrough:
5+
track: user
6+
order: 13
7+
---
8+
9+
User clients can check and manage the account's usernames.
10+
11+
## Checking a Username
12+
13+
Use {{ "checkUsername" |> m }} to check whether a username is available.
14+
15+
```ts
16+
const isAvailable = await client.checkUsername("example_username");
17+
18+
console.log(isAvailable);
19+
```
20+
21+
## Setting a Username
22+
23+
Use {{ "setUsername" |> m }} to set the account's username.
24+
25+
```ts
26+
await client.setUsername("example_username");
27+
```
28+
29+
## Showing a Username
30+
31+
Use {{ "showUsername" |> m }} to show a username on the account's profile.
32+
33+
```ts
34+
await client.showUsername("me", "example_username");
35+
```
36+
37+
## Hiding a Username
38+
39+
Use {{ "hideUsername" |> m }} to hide a username from the account's profile.
40+
41+
```ts
42+
await client.hideUsername("me", "example_username");
43+
```
44+
45+
## Reordering Usernames
46+
47+
Use {{ "reorderUsernames" |> m }} to change the order of the account's usernames.
48+
49+
```ts
50+
await client.reorderUsernames("me", ["primary_username", "example_username"]);
51+
```
52+
53+
## Removing a Username
54+
55+
Use {{ "removeUsername" |> m }} to remove the account's username.
56+
57+
```ts
58+
await client.removeUsername();
59+
```

0 commit comments

Comments
 (0)