Entering contact information in the Telegram Bot API

telegram bot api input contact message content
10 March 2025

Familiarity with InputContactMessageContent in the Telegram Bot API


Hello! Today we want to talk about one interesting concept in the Telegram Bot API. The name of this concept is InputContactMessageContent. This capability offers bots the ability to send information related to a contact. In general, if you have a Telegram bot and want to introduce a contact to users, this capability will be highly useful.


Imagine that you have a service bot and want to show the contact number to users. Instead of users manually entering their number, you can use InputContactMessageContent to send a contact in a proper way along with all the necessary information. This task provides users a more comfortable experience and also reduces input errors.


Using this capability is relatively easy. You need to format the contact information such as name, phone number, and... in a specific structure. Then send this information to your bot to be sent as a message. In this way, whenever the user clicks the contact button, they can directly use that contact number. This capability is especially useful for business and service bots.


In addition, we will review an example code of how to use InputContactMessageContent. This code includes an example message that sends contact information to the user. In the code below, you will see all the necessary steps to create and send this message.


Example Code


{
"chat_id": "@my_channel",
"reply_markup": {
"inline_keyboard": [[
{
"text": "Contact Us",
"callback_data": "contact"
}
]]
},
"text": "Contact us on Telegram",
"reply_to_message_id": 123,
"content": {
"type": "contact",
"first_name": "Ali",
"last_name": "Mohammadi",
"phone_number": "09121234567"
}
}

Code Descriptions


The above JSON code is a message structure for the Telegram Bot.

This code contains the contact information and the button to establish contact.


"chat_id": "@my_channel";

This line identifies which channel or chat the message should be sent to.


"reply_markup": { "inline_keyboard": ... }

Here, a button is defined for sending the message.


"text": "Contact us on Telegram";

The text message that will be displayed to the user.


"content": { "type": "contact", ... }

This section includes the details about the contact that we want to send.


"first_name": "Ali";

This line indicates the name of the individual.


"phone_number": "09121234567";

And finally, the phone number that the user can use to contact.

FAQ

?

What is InputContactMessageContent?

?

How can I add contact information to the Telegram bot?

?

Can I send more detailed contact information?

?

Is it necessary to include the user name?

?

What is the time duration for sending contact information?