# Telegram reply keyboard: ask for phone number and location

> Use a Telegram reply keyboard with request_contact and request_location, check that a shared contact is the sender's own, then remove the keyboard.

Published 2026-11-04. Z-API Omni team.

To get a user's phone number or location, send a message whose `reply_markup` is a `ReplyKeyboardMarkup` with a button set to `request_contact: true` or `request_location: true`. When the user taps it, your bot receives a normal message carrying a `contact` or a `location` object. Both buttons are "Available in private chats only" ([KeyboardButton](https://core.telegram.org/bots/api#keyboardbutton), accessed 2026-11-04). Before you store a phone number, check that `contact.user_id` matches the sender's `from.id`, then remove the keyboard. This post follows Bot API 10.3 (August 24, 2026). Telegram's reference has no JSON samples for the keyboard, contact or location objects, so every payload below is assembled from its field tables.

## Send the keyboard with sendMessage

A reply keyboard replaces the user's letter keyboard with your buttons. `keyboard` is an array of rows, and each row is an array of `KeyboardButton` objects ([ReplyKeyboardMarkup](https://core.telegram.org/bots/api#replykeyboardmarkup)). For a plain text button you can pass a string instead of an object. Pressing it sends that text as a message from the user.

```bash
curl -X POST "https://api.telegram.org/botYOUR_TOKEN/sendMessage" \
  -H "Content-Type: application/json" \
  -d '{
    "chat_id": YOUR_CHAT_ID,
    "text": "Share the phone number on your Telegram account so we can find your orders.",
    "reply_markup": {
      "keyboard": [
        [{"text": "Share my phone number", "request_contact": true}],
        [{"text": "Send my current location", "request_location": true}],
        ["Not now"]
      ],
      "resize_keyboard": true,
      "one_time_keyboard": true,
      "input_field_placeholder": "Tap a button below"
    }
  }'
```

Each button does one thing. Telegram allows "at most one of the fields other than text, icon_custom_emoji_id, and style" on a button, so `request_contact` and `request_location` go on separate buttons. Bot API 9.4 (February 9, 2026) added `style`, which takes `"danger"` (red), `"success"` (green) or `"primary"` (blue). If you omit it, the client picks its own style.

With a JSON body, `reply_markup` is a nested object, as above. With form encoding, send it as a JSON-serialized string. The same applies from the [Node.js bot](/academy/articles/telegram-bot-nodejs-getting-started/) or the [Python bot](/academy/articles/telegram-bot-send-message-python-getting-started/): put the object under `reply_markup` in the `sendMessage` parameters.

## The options that change how the keyboard behaves

| Field | Default | What it does ([ReplyKeyboardMarkup](https://core.telegram.org/bots/api#replykeyboardmarkup)) |
| --- | --- | --- |
| `is_persistent` | false | Keeps the keyboard visible when the regular keyboard is hidden; added in Bot API 6.4 |
| `resize_keyboard` | false | Shrinks the keyboard to fit its rows; otherwise it is as tall as the standard keyboard |
| `one_time_keyboard` | false | Hides the keyboard after one use; the user can still reopen it from the input field |
| `input_field_placeholder` | none | Placeholder text in the input field, 1 to 64 characters |
| `selective` | not set | Shows the keyboard only to users @mentioned in the text, or to the sender of the message you reply to |
| `force_reply` | not set | Opens the reply interface as if the user tapped Reply on your message; added in Bot API 10.3 |

Set `resize_keyboard` for a two- or three-button prompt. Without it, three short buttons stretch to the height of a full keyboard.

`one_time_keyboard` hides the keyboard but leaves it available. "By default, custom keyboards are displayed until a new keyboard is sent by a bot" ([ReplyKeyboardRemove](https://core.telegram.org/bots/api#replykeyboardremove)). A user who skips the prompt can reopen it days later and tap "Share my phone number" in a conversation that has moved on. Remove it explicitly once you have the answer, as shown further down.

Reply keyboards don't work in channels. They also don't work on messages sent on behalf of a business account ([ReplyKeyboardMarkup](https://core.telegram.org/bots/api#replykeyboardmarkup)). A bot answering through a business connection has to collect the number another way.

## Only in private chats

`request_contact`, `request_location`, `request_users` and `request_chat` all carry the same note: "Available in private chats only". Telegram doesn't document what happens if you send one to a group. It could be an API error or a button the client ignores. Check `message.chat.type === 'private'` before you attach the keyboard.

In a group, send the user to a private chat first. A deep link with a start parameter opens the bot's private chat. [Deep linking with the start parameter](/academy/articles/telegram-bot-deep-linking-start-parameter/) shows how to read that parameter and send the keyboard from there.

## Read the contact and confirm it's the sender's own

The tap arrives as a message with a `contact` field. `Contact` has `phone_number` and `first_name`, plus optional `last_name`, `user_id` and `vcard` ([Contact](https://core.telegram.org/bots/api#contact)).

`message.contact` describes any "shared contact". A user can also send your bot someone else's contact from their address book, and that arrives in the same field. Telegram doesn't document a check for this. Our reasoning from the field definitions is that `user_id` is optional, and only a `user_id` equal to `message.from.id` shows that the user shared their own number. Treat any other contact as a card the user passed along.

```javascript
// contact.mjs: returns the sender's own phone number, or null.
export function ownPhoneNumber(message) {
  const contact = message.contact;
  if (!contact || message.chat?.type !== 'private' || !message.from) return null;
  if (contact.user_id === undefined || contact.user_id !== message.from.id) return null;
  return '+' + contact.phone_number.replace(/\D/g, '');
}
```

The strict comparison is safe in JavaScript. Telegram says `user_id` "may have more than 32 significant bits" but "has at most 52 significant bits", so a 64-bit integer or a double holds it. A JavaScript number is a double. Store it as `BIGINT` in your database, not as a 32-bit `INT`.

The reference doesn't say whether `phone_number` starts with `+`. The function strips everything but digits and adds the `+` back, so your lookups compare one format. That normalization is our choice. Telegram doesn't document whether a contact shared through the button always carries `user_id`, so the function returns `null` when it's missing and your bot asks again.

## Read the location

A location tap arrives as `message.location`. `Location` has `latitude` and `longitude`, both floats "as defined by the sender", and an optional `horizontal_accuracy`, "the radius of uncertainty for the location, measured in meters; 0-1500" ([Location](https://core.telegram.org/bots/api#location)). The fields `live_period`, `heading` and `proximity_alert_radius` apply only to live locations.

The `Location` object has no field that says your button produced it. If the coordinates feed a delivery address, show the user what you understood and let them confirm. A large `horizontal_accuracy` is a reason to ask for a street address as well.

## Remove the keyboard after the answer

Send `ReplyKeyboardRemove` with your confirmation message. Telegram clients then "remove the current custom keyboard and display the default letter-keyboard".

```bash
curl -X POST "https://api.telegram.org/botYOUR_TOKEN/sendMessage" \
  -H "Content-Type: application/json" \
  -d '{"chat_id": YOUR_CHAT_ID, "text": "Thanks, your number is saved.", "reply_markup": {"remove_keyboard": true}}'
```

After `remove_keyboard`, the "user will not be able to summon this keyboard". That's the difference from `one_time_keyboard`, which only hides it. Handle the "Not now" button the same way. It arrives as a text message reading `Not now`, and your reply should remove the keyboard too.

## Ask for another user or a chat

The same keyboard can ask the user to pick people or a chat. A `request_users` button "will open a list of suitable users", and the bot receives their identifiers in a `users_shared` service message. A `request_chat` button does the same for a chat and sends a `chat_shared` service message ([KeyboardButtonRequestUsers](https://core.telegram.org/bots/api#keyboardbuttonrequestusers), [KeyboardButtonRequestChat](https://core.telegram.org/bots/api#keyboardbuttonrequestchat)).

```json
{
  "keyboard": [
    [{"text": "Pick teammates", "request_users": {"request_id": 1, "user_is_bot": false, "max_quantity": 3, "request_username": true}}],
    [{"text": "Pick a group to connect", "request_chat": {"request_id": 2, "chat_is_channel": false, "bot_is_member": true, "request_title": true}}]
  ],
  "resize_keyboard": true,
  "one_time_keyboard": true
}
```

`request_id` is a signed 32-bit number that "must be unique within the message", and it comes back in `users_shared.request_id` or `chat_shared.request_id`. Use it to tell which button the user pressed. `max_quantity` runs from 1 to 10 and defaults to 1. Names, usernames and photos appear in `SharedUser` only if you set `request_name`, `request_username` or `request_photo`. In Bot API 7.0 the older `request_user` field became `request_users`, so update any code that still sends the singular.

An identifier alone may not be enough. Telegram's features page warns that the bot "may not be able to use the identifier it receives". That happens when the chat or user "is not already known or accessible by some other means" ([Bot features](https://core.telegram.org/bots/features), accessed 2026-11-04). Store the IDs, but test that a call with one works before your flow depends on it.

Reply keyboards send text or shared data as a new message from the user. Buttons that sit under one of your messages and trigger a callback are a different object, covered in [inline keyboards and callback queries](/academy/articles/telegram-bot-inline-keyboards-callback-queries/).

*Z-API Omni team*
