How to connect the Telegram Bot API to Google Sheets

A Telegram Bot is a programe that behaves like a normal chat partner with additional functions. It performs predefined tasks independently and without the user’s involvement. The term bot is derived from the term for robot. We can use the Telegram Bot API to import data from Telegram Bot into Google Sheets. In this tutorial, we’ll show you how to connect the Telegram Bot REST API to Google Sheets in 5 steps:

  1. Install the Apipheny add-on
  2. Create new bot and obtain the access token
  3. Choose a Telegram Bot API endpoint
  4. Enter your Telegram Bot API request into Apipheny
  5. Run the Telegram Bot API request in your Google Sheet

Step 1.) Install and open the Apipheny add-on for Google Sheets

Apipheny is a free API connector for Google Sheets. You can use Apipheny to connect your Google Sheets to API data sources, easily.

1.) Install Apipheny by opening the following link on desktop and then clicking the Install button in the Google Marketplace: https://apipheny.io/install

2.) After you’ve installed Apipheny, open a Google Sheet and then click on the Extensions dropdown in the menu at the top.

In the dropdown list you should see Apipheny. Click Apipheny then click Import API to open the Apipheny sidebar in your Google Sheet.

open apipheny

Tip: you can open a new Google Sheet by entering this URL in your browser: sheet.new

Step 2.) Create new bot and obtain the access token

In your Telegram app, Enter @Botfather in the search tab and choose this bot.

Note: Official Telegram bots have a blue checkmark beside their name.

Searching the BotFather
Searching the BotFather

Click “Start” to activate BotFather bot:

Activating the BotFather
Activating the BotFather

In response, you receive a list of commands to manage bots.

Choose or type the /newbot command and send it.

Creating a new bot
Creating a new bot

Choose a name for your bot — your subscribers will see it in the conversation:

Choosing a name for the new bot
Choosing a name for the new bot

And choose a username for your bot — the bot can be found by its username in searches. The username must be unique and end with the word “bot”:

Choosing a username for the new bot
Choosing a username for the new bot

After you choose a suitable name for your bot — the bot is created. The token will be displayed in this last message:

The token is displayed on the screen
The token is displayed on the screen

Copy the token to a safe location because you’ll need it later.

Step 3.) Choose a Telegram Bot API endpoint

In this section, we’ll show you how to browse the Telegram Bot API documentation to find the endpoint URL that retrieves the information you need from your Telegram account.

If you already know your API URL, or you want to use the same example URL as us, just skip to Step 4.

To choose an endpoint, first open the Telegram Bot API documentation page: https://core.telegram.org/bots/api#available-methods

The main section contains all the available methods (endpoints) for the Telegram Bot API with their descriptions. The right menu contains a list of these methods for easy finding:

Telegram Bot API documentation page
Telegram Bot API documentation page

In this case, we will describe the getUserProfilePhotos method (endpoint), which get a list of profile pictures for a user:

https://api.telegram.org/botTOKEN/getUserProfilePhotos

Don’t forget to replace TOKEN with your own token.

The documentation for this endpoint contains its HTTP, a short description of the endpoint’s purpose and the required/optional parameters if any:

getUserProfilePhotos endpoint's documentation
getUserProfilePhotos endpoint’s documentation

All API calls to the Telegram Bot should be made using the https://api.telegram.org/bot base domain. All endpoints and parameters would be appended to this base domain.

Step 4.) Enter your Telegram Bot API Request into Apipheny

Now go back to your Google Sheet and make sure that the Apipheny add-on is open, on the Import tab.

In the Import Tab, enter these details into the add-on:

Method: At the top of the Apipheny sidebar, select the HTTP method (GET, POST, PUT, PATCH or DELETE) required by your API endpoint. For this example, we are using the GET method.

API URL: In Step 3, we explained how you can find the Telegram Bot API endpoint that you need. Now copy the complete URL into the Apipheny add-on, where it says API URL Path, followed by any GET parameters required for your query.

For this example, we are using the getMyName endpoint, which displays the current bot name for the given user language. The URL for this API endpoint is:

https://api.telegram.org/TOKEN/getMyName

Don’t forget to replace TOKEN with the token you obtained in Step 2.)

Headers: The Headers section of the Apipheny add-on will be left blank.

Here’s what your Telegram Bot API request should look like when entered into Apipheny, if you’re following the same example as us:

Telegram Bot API request entered in the Apipheny add-on
Telegram Bot API request entered in the Apipheny add-on

Step 5.) Run the Telegram Bot API Request in your Google Sheet

The last step is to click the Run button at the bottom of the Apipheny add-on and then your Telegram data will be imported into your Google Sheet:

Telegram Bot data imported into Google Sheets using the Apipheny add-on
Telegram Bot data imported into Google Sheets using the Apipheny add-on

Crypto API Tutorials:


Popular API Tutorials


API Knowledge

What is an API?

What is an API URL?

What are parameters?

What is an endpoint?

What is an API key/token?

What is basic authentication?

What are headers?

What is a GET request?

What is a POST request?