|
| 1 | +--- |
| 2 | +title: Gifts |
| 3 | +parent: /#walkthrough |
| 4 | +walkthrough: |
| 5 | + track: main |
| 6 | + order: 22 |
| 7 | +--- |
| 8 | + |
| 9 | +Clients can browse, send, sell, and transfer Telegram Star gifts. |
| 10 | + |
| 11 | +## Getting Available Gifts |
| 12 | + |
| 13 | +Use {{ "getGifts" |> m }} to list the gifts available for purchase. |
| 14 | + |
| 15 | +```ts |
| 16 | +const gifts = await client.getGifts(); |
| 17 | + |
| 18 | +for (const gift of gifts) { |
| 19 | + console.log(gift.id, gift.price); |
| 20 | +} |
| 21 | +``` |
| 22 | + |
| 23 | +`id` is the identifier used when sending a gift. |
| 24 | + |
| 25 | +## Getting a Gift |
| 26 | + |
| 27 | +Use {{ "getGift" |> m }} with a gift slug to fetch its details. |
| 28 | + |
| 29 | +```ts |
| 30 | +const gift = await client.getGift("delicious-bento"); |
| 31 | +``` |
| 32 | + |
| 33 | +## Sending a Gift |
| 34 | + |
| 35 | +Use {{ "sendGift" |> m }} with the recipient and the gift identifier to purchase and send a gift. |
| 36 | + |
| 37 | +```ts |
| 38 | +await client.sendGift(userId, giftId); |
| 39 | +``` |
| 40 | + |
| 41 | +Optionally, pass a `message` to attach text to the gift. |
| 42 | + |
| 43 | +```ts |
| 44 | +await client.sendGift(userId, giftId, { |
| 45 | + message: "Enjoy!", |
| 46 | +}); |
| 47 | +``` |
| 48 | + |
| 49 | +## Selling a Gift |
| 50 | + |
| 51 | +Use {{ "sellGift" |> m }} to convert a saved gift to Telegram Stars. Reference the gift by its chat and identifier. |
| 52 | + |
| 53 | +```ts |
| 54 | +await client.sellGift({ type: "chat", chatId, id }); |
| 55 | +``` |
| 56 | + |
| 57 | +For a gift in a private chat, use `type: "user"` with the `messageId`. |
| 58 | + |
| 59 | +```ts |
| 60 | +await client.sellGift({ type: "user", messageId }); |
| 61 | +``` |
| 62 | + |
| 63 | +## Transferring a Gift |
| 64 | + |
| 65 | +Use {{ "transferGift" |> m }} to give a saved gift to another user. |
| 66 | + |
| 67 | +```ts |
| 68 | +await client.transferGift(userId, { type: "chat", chatId, id }); |
| 69 | +``` |
0 commit comments