stopMessageLiveLocation
Use this method to stop updating a live location message before live_period expires. On success, if the message is not an inline message, the edited Message is returned, otherwise True is returned.
Parameters
business_connection_idStringOptionalUnique identifier of the business connection on behalf of which the message to be edited was sent
chat_idIntegerStringOptionalRequired if inline\message\id is not specified. Unique identifier for the target chat or username of the target channel (in the format
@channelusername)message_idIntegerOptionalRequired if inline\message\id is not specified. Identifier of the message with live location to stop
inline_message_idStringOptionalRequired if chat\id and message\id are not specified. Identifier of the inline message
A JSON-serialized object for a new inline keyboard.
Returns
On success, Message | True is returned.
GramIO Usage
ts
// Stop a live location in a regular chat message
await bot.api.stopMessageLiveLocation({
chat_id: 123456789,
message_id: 42,
});ts
// Stop and replace the keyboard with a "Location ended" button
await bot.api.stopMessageLiveLocation({
chat_id: 123456789,
message_id: 42,
reply_markup: new InlineKeyboard().text("Location ended", "location_ended"),
});ts
// Stop a live location sent via inline query (no chat_id needed)
await bot.api.stopMessageLiveLocation({
inline_message_id: "AAABB-xyz...",
});ts
// Typical pattern: track the message_id when sending, stop it later
const locationMsg = await bot.api.sendLocation({
chat_id: 123456789,
latitude: 48.8566,
longitude: 2.3522,
live_period: 300, // 5 minutes
});
// ... time passes or user stops sharing ...
await bot.api.stopMessageLiveLocation({
chat_id: locationMsg.chat.id,
message_id: locationMsg.message_id,
});Errors
| Code | Error | Cause |
|---|---|---|
| 400 | Bad Request: chat not found | Invalid or inaccessible chat_id |
| 400 | Bad Request: message not found | The message_id doesn't exist in the chat |
| 400 | Bad Request: message can't be edited | The message is not a live location, or the live period has already expired — the location stopped automatically |
| 400 | Bad Request: message is not modified | The live location is already stopped and reply_markup is identical to the current one |
| 429 | Too Many Requests: retry after N | Rate limit hit — check retry_after, use auto-retry plugin |
TIP
Use GramIO's auto-retry plugin to handle 429 errors automatically.
Tips & Gotchas
chat_id+message_idORinline_message_id— not both. For regular messages usechat_id+message_id; for messages sent via inline query useinline_message_idonly.- Returns
Messagefor regular messages,truefor inline. The return value differs based on which identifier pair you use. Narrowing the type in TypeScript requires checkingtypeof result === "boolean". - You can update
reply_markupon stop. This is useful for replacing location-specific buttons (like "Stop sharing") with a static button (like "Location ended") in one atomic call. - Calling on an already-stopped location returns an error. If the
live_periodhas expired or the location was already stopped, Telegram returnsmessage can't be edited. Catch this error gracefully. - Store the message ID when sending. You need the original
message_idto stop the live location later — save it in your session or database when the location message is first sent.
See Also
- sendLocation — send a live location (with
live_period) - editMessageLiveLocation — update the location coordinates while it's still live
- Message — returned for non-inline messages
- InlineKeyboardMarkup — keyboard structure for
reply_markup - Keyboards guide — building inline keyboards with GramIO