Method Chaining¶
Send a message with Api, get back an object you can act on immediately — edit it, reply to it, pin it, delete it — without hunting for message_id and chat_id like a scavenger hunt.
let sent = await Api.sendMessage({ text: "Hello." })
await sent.pin()
await sent.react("👍")
await sent.editText("Updated.")
await sent.reply("Follow-up.")
await sent.delete()
Each chained method maps to the Telegram API call you'd otherwise write by hand. Less boilerplate, more bot-building.
What supports chaining?¶
Chaining comes from message-sending Api methods — sendMessage, sendPhoto, and similar. Not every Api call returns a chainable object. getMe gives you data; sendMessage gives you something you can keep working with.
If you're unsure, await the send and try — if chaining methods exist on the result, you're good.
New to TBL?
Bot, chat, and user are globals available in every command. Quick intro: Learning TBL.
How to use it¶
Send, edit, delete — the classic trio¶
let sent = await Api.sendMessage({ text: "Temporary." })
await sent.editText("This will disappear.")
await sent.delete()
Works with Bot.sendMessage too when awaited:
Pin silently, react, reply¶
let sent = await Api.sendMessage({ text: "Important announcement." })
await sent.pin(true) // true = disable notification
await sent.react("🎉")
await sent.reply("Questions? Reply here.")
Available chained methods¶
Editing and updating¶
editText(text, {...options})editCaption(caption, {...options})editMedia(media, {...options})editReplyMarkup(rm, {...options})
Message control¶
delete()pin(dn = false)— passtrueto pin silentlyunpin()
Reactions¶
react(emoji, big = false)
Forwarding and copying¶
forward(to, {...options})copy(to, {...options})
Reply methods¶
reply(text, {...options})replyPhoto(photo, {...options})replyVideo(video, {...options})replyAudio(audio, {...options})replyVoice(voice, {...options})replyDocument(doc, {...options})replySticker(sticker, {...options})replyAnimation(anim, {...options})replyLocation(lat, lon, {...options})replyContact(phone, fn, {...options})replyPoll(q, options, {...options})replyDice(emoji = "", {...options})
Info and utilities¶
get()— message id and metadatadownloadFile()— download URL for attached media, if any
Live location and polls¶
editLiveLocation(lat, lon, {...options})stopLiveLocation({...options})stopPoll({...options})
Important notes¶
- Chaining only applies to message-sending
Apiresponses (andBotsend methods when awaited) - Other methods return plain response objects — no
.editText()ongetMe - You need
awaiton the initial send to get the chainable object
Note
Chaining only applies to message-sending Api responses. Other methods return plain response objects.
See also¶
- Editing Messages — same edits via standalone
Apicalls - Async Requests — why
awaitmatters here