How do I get and save a phone number from Telegram in n8n? I’m using n8n locally for learning purposes. The issue is that I’m sending a keyboard with request_number=true to request a phone number, but I don’t understand how to get this number. When I click “Share number” in Telegram, the process in n8n already completes and doesn’t wait for my response. Wait nodes also don’t help as they return old responses without the contact. How do I properly configure getting phone numbers in n8n when working with Telegram?
Getting Phone Numbers from Telegram in n8n
To retrieve a phone number from Telegram in n8n, you need to use the correct combination of Telegram Trigger and Wait for Webhook nodes, configuring them to handle callback requests when a contact is shared. The key issue is that Telegram sends a callback request immediately when the “Share number” button is pressed, and n8n must be configured to handle this rather than waiting for a regular message.
Contents
- Basic Approach to Getting Phone Numbers
- Telegram Trigger Setup
- Using Wait for Webhook
- Callback Request Handling
- Complete Workflow Example
- Common Issues
- Alternative Methods
Basic Approach to Getting Phone Numbers
To get a phone number from Telegram in n8n, you need to understand how request_number buttons work. When a user presses “Share number”, Telegram sends a callback request, not a regular message. Therefore, the standard Telegram Trigger won’t work properly.
The correct approach includes:
- Using a Telegram Trigger configured to listen for callback requests
- Setting up Wait for Webhook to wait for the response from Telegram
- Processing the received callback request and extracting the phone number
- Saving the number in the required format
Important: When setting request_number=true in inline keyboard, Telegram sends a callback_query that contains information about the button press but not the phone number itself. The phone number needs to be requested separately after receiving the callback.
Telegram Trigger Setup
To properly set up phone number retrieval in n8n, follow these steps:
-
Add a Telegram Trigger node to the canvas
-
In the node settings, select the “On Trigger” operation
-
In the “Choose Trigger” section, set:
- Bot Token (your Telegram bot token)
- Trigger Type: “Callback Query”
- Webhook URL: your local URL for receiving webhooks (e.g.,
http://localhost:5678/webhook/telegram)
-
In Security settings:
- Check the “Validate Certificate” box
- In the “Secret” field, enter a secret key for webhook signing
{
"operation": "onTrigger",
"parameters": {
"botToken": "your_bot_token",
"webhookUrl": "http://localhost:5678/webhook/telegram",
"secret": "your_secret_key",
"validateCertificate": true
}
}
Using Wait for Webhook
After receiving a callback request, you need to wait for the response from Telegram with the phone number:
-
Add a Wait for Webhook node after the Telegram Trigger
-
Configure its parameters:
- Webhook Name:
telegram_phone_response(unique name) - Timeout: 30000 (30 seconds)
- Continue On Timeout: false
- Webhook Name:
-
In the “Response Type” section, select “JSON”
-
In the “Response Mapping” settings, specify the path to the phone number data
{
"operation": "waitForWebhook",
"parameters": {
"webhookName": "telegram_phone_response",
"timeout": 30000,
"continueOnTimeout": false,
"responseType": "json",
"responseMapping": {
"phoneNumber": "$.data.contact.phone_number"
}
}
}
Callback Request Handling
When receiving a callback request from Telegram containing information about the “Share number” button press, you need to:
- Identify the callback: The callback_query data will contain a
datafield with information about the pressed button - Send a request to get the contact: Use Telegram API’s
getContactmethod - Process the received contact: Extract the phone number from the contact object
Example processing in a Set node:
{
"operation": "set",
"parameters": {
"values": {
"callbackId": "={{ $json.callback_query.id }}",
"chatId": "={{ $json.callback_query.message.chat.id }}",
"buttonData": "={{ $json.callback_query.data }}",
"requestContact": "={{ $json.callback_query.data.includes('request_contact') }}"
}
}
}
Then use an HTTP Request node to call the Telegram API method:
{
"operation": "httpRequest",
"parameters": {
"url": "https://api.telegram.org/bot{{ $credentials.telegramBotToken }}/getContact",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"body": {
"chat_id": "={{ $json.chatId }}",
"user_id": "={{ $json.callback_query.from.id }}"
}
}
}
Complete Workflow Example
Here’s a complete workflow example for getting a phone number:
- Telegram Trigger (configured for callback_query)
- Set (extracting data from callback)
- HTTP Request (getting contact via Telegram API)
- Set (saving phone number)
- HTTP Response (sending response to user)
graph TD
A[Telegram Trigger] --> B[Set - Data Extraction]
B --> C{Has callback?}
C -->|Yes| D[HTTP Request - getContact]
C -->|No| E[Waiting for response]
D --> F[Set - Saving Number]
F --> G[HTTP Response - Confirmation]
G --> A
Setup Steps:
-
Telegram Trigger
- Bot Token: your token
- Trigger Type: Callback Query
- Webhook URL: your local URL
-
Set Node 1
json{ "callbackId": "={{ $json.callback_query.id }}", "chatId": "={{ $json.callback_query.message.chat.id }}", "buttonData": "={{ $json.callback_query.data }}" } -
HTTP Request Node
json{ "url": "https://api.telegram.org/bot{{ $credentials.telegramBotToken }}/getChat", "method": "POST", "body": { "chat_id": "={{ $json.chatId }}", "user_id": "={{ $json.callback_query.from.id }}" } } -
Set Node 2
json{ "phoneNumber": "={{ $json.result.contact.phone_number }}", "firstName": "={{ $json.result.contact.first_name }}", "lastName": "={{ $json.result.contact.last_name }}" } -
HTTP Response Node
json{ "callbackQueryId": "={{ $json.callbackId }}", "text": "Thank you! Your phone number has been saved." }
Common Issues
Issue 1: Process terminates before receiving the number
Solution: Use Wait for Webhook with proper callback configuration. Ensure your Telegram Trigger is set up to receive callback_query, not regular messages.
Issue 2: Wait returns old response
Solution: Configure Wait for Webhook for a specific callback by using a unique webhook name for each request.
Issue 3: Multiple triggers don’t work
Solution: As noted in the n8n documentation, due to Telegram API limitations, you can only use one Telegram Trigger for each bot simultaneously. Use one trigger with different processing types.
Issue 4: Phone number not extracted
Solution: Check the structure of the Telegram API response. The phone number is typically located in $json.result.contact.phone_number when using the getChat method.
Alternative Methods
Method 1: Using Contact Sharing
If the standard method doesn’t work, you can use the built-in contact sharing feature:
- Create an inline keyboard with a “Share contact” button
- In the button settings, set
request_contact: true - Configure Telegram Trigger to receive messages with contacts
{
"inline_keyboard": [
[
{
"text": "Share number",
"request_contact": true,
"callback_data": "share_contact"
}
]
]
}
Method 2: Using Custom Forms
As mentioned in the n8n documentation, you can use custom forms:
- Create a form with a phone number input field
- Use Telegram Trigger to receive messages
- Validate the phone number format in n8n
Method 3: HTTP Request + Telegram API
For more complex scenarios, you can directly call the Telegram API via the HTTP Request node:
{
"operation": "httpRequest",
"parameters": {
"url": "https://api.telegram.org/bot{{ $credentials.telegramBotToken }}/sendMessage",
"method": "POST",
"body": {
"chat_id": "={{ $json.chat_id }}",
"text": "Please share your phone number",
"reply_markup": {
"keyboard": [
[
{
"text": "Share number",
"request_contact": true
}
]
],
"one_time_keyboard": true,
"resize_keyboard": true
}
}
}
}
Conclusion
Getting phone numbers from Telegram in n8n requires proper configuration of callback request handling. Key points:
- Use the correct Trigger: Configure Telegram Trigger to receive callback_query, not regular messages
- Handle callbacks immediately: When a user presses “Share number”, Telegram sends a callback that needs to be processed right away
- Use Wait for Webhook: To wait for contact data response
- Process data correctly: Extract the phone number from the Telegram API response
- Consider API limitations: Remember that only one Telegram Trigger can be used per bot
For local development, ensure your n8n server is accessible from the internet or use ngrok to create a public URL for the webhook. This will allow Telegram to send callback requests to your local n8n instance.
Sources
- Telegram node Callback operations documentation | n8n Docs
- Telegram - can’t use query buttons and callbacks - by design - Questions - n8n Community
- Ask a question via Telegram and wait for response? - Questions - n8n Community
- Telegram node Message operations documentation | n8n Docs
- n8n Telegram Bot Integration - MpireSolutions