Skip to content

Commit 76ea275

Browse files
committed
Add more Walkthrough sections
1 parent 51fece2 commit 76ea275

11 files changed

Lines changed: 736 additions & 0 deletions

src/chat-members.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
title: Chat Members
3+
parent: /#walkthrough
4+
prev: /topics
5+
next: /invite-links-and-join-requests
6+
---
7+
8+
Chat members are represented by {{ "ChatMember" |> t }} objects. Each object contains the member and their status in the chat.
9+
10+
## Listing Members
11+
12+
Use {{ "getChatMembers" |> m }} to list the members of a group, supergroup, or channel.
13+
14+
```ts
15+
const members = await client.getChatMembers(chatId);
16+
17+
for (const { member, status } of members) {
18+
console.log(member.id, status);
19+
}
20+
```
21+
22+
Use {{ "getChatMember" |> m }} to retrieve one member.
23+
24+
```ts
25+
const member = await client.getChatMember(chatId, userId);
26+
```
27+
28+
## Handling Membership Changes
29+
30+
The `chatMember` update contains the previous and current state of a member.
31+
32+
```ts
33+
client.on("chatMember", (ctx) => {
34+
const { oldChatMember, newChatMember } = ctx.update.chatMember;
35+
console.log(oldChatMember.status, newChatMember.status);
36+
});
37+
```
38+
39+
Use the `myChatMember` update to handle changes to the current account's membership.
40+
41+
## Restricting a Member
42+
43+
Use {{ "setChatMemberRights" |> m }} to restrict a member of a supergroup.
44+
45+
```ts
46+
await client.setChatMemberRights(chatId, userId, {
47+
rights: {
48+
canSendMessages: false,
49+
},
50+
});
51+
```
52+
53+
Set `until` to a future Unix timestamp in seconds to make the restriction temporary.
54+
55+
## Promoting a Member
56+
57+
Use {{ "promoteChatMember" |> m }} to grant administrator rights.
58+
59+
```ts
60+
await client.promoteChatMember(chatId, userId, {
61+
canDeleteMessages: true,
62+
canManageTopics: true,
63+
});
64+
```
65+
66+
## Removing a Member
67+
68+
Ban a member to prevent them from rejoining. Unban them to allow them to join again.
69+
70+
```ts
71+
await client.banChatMember(chatId, userId);
72+
await client.unbanChatMember(chatId, userId);
73+
```
74+
75+
Use {{ "kickChatMember" |> m }} to remove a member without keeping them banned.
76+
77+
```ts
78+
await client.kickChatMember(chatId, userId);
79+
```

src/chat-settings.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: Chat Settings
3+
parent: /#walkthrough
4+
prev: /invite-links-and-join-requests
5+
next: /secret-chats
6+
---
7+
8+
Administrators can change a chat's details and behavior.
9+
10+
## Changing the Title and Description
11+
12+
Use {{ "setChatTitle" |> m }} and {{ "setChatDescription" |> m }} to update a group, supergroup, or channel.
13+
14+
```ts
15+
await client.setChatTitle(chatId, "MTKruto Community");
16+
await client.setChatDescription(chatId, "A place to discuss MTKruto.");
17+
```
18+
19+
Set the description to an empty string to remove it.
20+
21+
## Changing the Photo
22+
23+
```ts
24+
await client.setChatPhoto(chatId, "./community.jpg");
25+
```
26+
27+
Use {{ "deleteChatPhoto" |> m }} to remove the current photo.
28+
29+
```ts
30+
await client.deleteChatPhoto(chatId);
31+
```
32+
33+
## Enabling Slow Mode
34+
35+
User clients can use {{ "setSlowMode" |> m }} to limit how often members can send messages in a supergroup.
36+
37+
```ts
38+
await client.setSlowMode(chatId, "30s");
39+
```
40+
41+
See {{ "SlowModeDuration" |> t }} for the available durations. Use {{ "disableSlowMode" |> m }} to turn slow mode off.
42+
43+
## Automatically Deleting Messages
44+
45+
User clients can use {{ "setMessageTtl" |> m }} to automatically delete messages after a number of seconds.
46+
47+
```ts
48+
await client.setMessageTtl(chatId, 7 * 24 * 60 * 60);
49+
```

src/checklists.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: Checklists
3+
parent: /#walkthrough
4+
prev: /polls
5+
next: /scheduled-messages
6+
---
7+
8+
Checklists let users track tasks in a chat. Use {{ "sendChecklist" |> m }} with a title and an array of {{ "InputChecklistItem" |> t }} objects.
9+
10+
## Sending a Checklist
11+
12+
```ts
13+
const message = await client.sendChecklist(chatId, "Release checklist", [
14+
{ text: "Run the tests" },
15+
{ text: "Update the documentation" },
16+
{ text: "Publish the release" },
17+
]);
18+
```
19+
20+
Within an update handler, use `ctx.replyChecklist` to send a checklist to the current chat.
21+
22+
## Letting Others Update a Checklist
23+
24+
By default, only the creator can add or complete items. Set `isExtendableByOthers` and `isCompletableByOthers` to let other users do so.
25+
26+
```ts
27+
await client.sendChecklist(chatId, "Trip planning", [
28+
{ text: "Book accommodation" },
29+
{ text: "Choose activities" },
30+
], {
31+
isExtendableByOthers: true,
32+
isCompletableByOthers: true,
33+
});
34+
```
35+
36+
## Reading a Checklist
37+
38+
Checklist messages contain their title, items, and permissions in `message.checklist`.
39+
40+
```ts
41+
client.on("message:checklist", (ctx) => {
42+
console.log(ctx.msg.checklist.title);
43+
44+
for (const item of ctx.msg.checklist.items) {
45+
console.log(item.id, item.text, item.type);
46+
}
47+
});
48+
```
49+
50+
An item's `type` is either `"checked"` or `"unchecked"`. Checked items also include the user who completed them and the completion time.
51+
52+
## Updating a Checklist
53+
54+
User clients can check and uncheck items by their identifiers.
55+
56+
```ts
57+
const itemId = message.checklist.items[0].id;
58+
59+
await client.checkChecklistItem(chatId, message.id, itemId);
60+
await client.uncheckChecklistItem(chatId, message.id, itemId);
61+
```
62+
63+
Use {{ "checkChecklistItems" |> m }} and {{ "uncheckChecklistItems" |> m }} to update multiple items. Use {{ "addToChecklist" |> m }} to append items.
64+
65+
```ts
66+
await client.addToChecklist(chatId, message.id, [
67+
{ text: "Announce the release" },
68+
]);
69+
```

src/index.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ Its key features include:
3535
10. [Files](/files) {{ "/files" |> i }}
3636
11. [Inline Queries](/inline-queries) {{ "/inline-queries" |> i }}
3737
12. [Rich Messages and Text Formatting](/rich-messages-and-text-formatting) {{ "/rich-messages-and-text-formatting" |> i }}
38+
13. [Polls](/polls) {{ "/polls" |> i }}
39+
14. [Checklists](/checklists) {{ "/checklists" |> i }}
40+
15. [Scheduled Messages](/scheduled-messages) {{ "/scheduled-messages" |> i }}
41+
16. [Stories](/stories) {{ "/stories" |> i }}
42+
17. [Topics](/topics) {{ "/topics" |> i }}
43+
18. [Chat Members](/chat-members) {{ "/chat-members" |> i }}
44+
19. [Invite Links and Join Requests](/invite-links-and-join-requests) {{ "/invite-links-and-join-requests" |> i }}
45+
20. [Chat Settings](/chat-settings) {{ "/chat-settings" |> i }}
46+
21. [Secret Chats](/secret-chats) {{ "/secret-chats" |> i }}
3847

3948
### Guides
4049

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: Invite Links and Join Requests
3+
parent: /#walkthrough
4+
prev: /chat-members
5+
next: /chat-settings
6+
---
7+
8+
Invite links let people join a group, supergroup, or channel.
9+
10+
## Creating an Invite Link
11+
12+
Use {{ "createInviteLink" |> m }} to create an invite link.
13+
14+
```ts
15+
const inviteLink = await client.createInviteLink(chatId, {
16+
title: "Community invite",
17+
limit: 100,
18+
});
19+
20+
console.log(inviteLink.inviteLink);
21+
```
22+
23+
Set `expireAt` to a future Unix timestamp in seconds to make the link temporary.
24+
25+
## Requiring Approval
26+
27+
Set `isApprovalRequired` to make users send a join request instead of joining immediately. It cannot be used together with `limit`.
28+
29+
```ts
30+
const inviteLink = await client.createInviteLink(chatId, {
31+
isApprovalRequired: true,
32+
});
33+
```
34+
35+
User clients can use {{ "enableJoinRequests" |> m }} and {{ "disableJoinRequests" |> m }} to enable or disable join requests for a channel or supergroup.
36+
37+
## Handling Join Requests
38+
39+
Bots receive a `joinRequest` update containing the chat and the user who requested to join.
40+
41+
```ts
42+
client.on("joinRequest", async (ctx) => {
43+
const { chat, from } = ctx.update.joinRequest;
44+
await client.approveJoinRequest(chat.id, from.id);
45+
});
46+
```
47+
48+
Use {{ "declineJoinRequest" |> m }} to decline a request instead.
49+
50+
## Listing Join Requests
51+
52+
User clients can list pending requests with {{ "getJoinRequests" |> m }}.
53+
54+
```ts
55+
const requests = await client.getJoinRequests(chatId);
56+
57+
for (const request of requests) {
58+
console.log(request.from.id, request.date);
59+
}
60+
```
61+
62+
Use {{ "approveJoinRequests" |> m }} or {{ "declineJoinRequests" |> m }} to handle all pending requests at once.

src/polls.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: Polls
3+
parent: /#walkthrough
4+
prev: /rich-messages-and-text-formatting
5+
next: /checklists
6+
---
7+
8+
Polls let users choose from a list of options directly in a chat. Use {{ "sendPoll" |> m }} with a question and an array of {{ "InputPollOption" |> t }} objects.
9+
10+
## Sending a Poll
11+
12+
```ts
13+
const message = await client.sendPoll(
14+
chatId,
15+
"Which runtime do you use?",
16+
[
17+
{ text: "Deno" },
18+
{ text: "Node.js" },
19+
{ text: "Bun" },
20+
],
21+
);
22+
```
23+
24+
Polls are anonymous by default. Set `isAnonymous` to `false` when individual votes must be visible. Regular polls can also allow more than one answer.
25+
26+
```ts
27+
await client.sendPoll(chatId, "Which runtimes do you use?", [
28+
{ text: "Deno" },
29+
{ text: "Node.js" },
30+
{ text: "Bun" },
31+
], {
32+
isAnonymous: false,
33+
isMultipleAnswersAllowed: true,
34+
});
35+
```
36+
37+
Within an update handler, use `ctx.replyPoll` to send the poll to the current chat.
38+
39+
## Sending a Quiz
40+
41+
A quiz has one or more correct options. Set `type` to `"quiz"` and provide their zero-based indexes. The optional explanation is shown after an answer is submitted.
42+
43+
```ts
44+
await client.sendPoll(chatId, "What does MTProto power?", [
45+
{ text: "Telegram" },
46+
{ text: "Matrix" },
47+
], {
48+
type: "quiz",
49+
correctOptionIndexes: [0],
50+
explanation: "MTProto is Telegram's protocol.",
51+
});
52+
```
53+
54+
## Handling Poll Updates
55+
56+
The `poll` update contains the latest state of a poll, including its options and total voter count.
57+
58+
```ts
59+
client.on("poll", (ctx) => {
60+
const { options, totalVoterCount } = ctx.update.poll;
61+
console.log(options, totalVoterCount);
62+
});
63+
```
64+
65+
For non-anonymous polls, `pollAnswer` contains the voter and the indexes they selected.
66+
67+
```ts
68+
client.on("pollAnswer", (ctx) => {
69+
const { pollId, from, optionIndexes } = ctx.update.pollAnswer;
70+
console.log(pollId, from, optionIndexes);
71+
});
72+
```
73+
74+
## Stopping a Poll
75+
76+
Stop a poll with {{ "stopPoll" |> m }}. No more answers can be submitted after it is stopped.
77+
78+
```ts
79+
await client.stopPoll(chatId, message.id);
80+
```

src/rich-messages-and-text-formatting.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title: Rich Messages and Text Formatting
33
parent: /#walkthrough
44
prev: /inline-queries
5+
next: /polls
56
---
67

78
MTKruto supports both rich messages and formatted text messages. Rich messages contain structured page content such as headings, paragraphs, lists, tables, and media. Regular messages and media captions remain strings, with formatting described by message entities.

0 commit comments

Comments
 (0)