|
| 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 | +``` |
0 commit comments