Overview
Discover how TelePilot enables you to streamline your searches through Telegram and seamlessly save the results for future use.
Whether you prefer to build your own workflow or directly download and import our pre-designed workflow file, we’ve got you covered: TelePilot__Search
The n8n Workflow

We’ll be using the following straightforward algorithm:
- Execute the
searchPublicChatsTelegram action using the Telegram CoPilot node, which returns a list ofchat_ids. - Carry out some necessary utility work and transformations.
- Run
getChatfor each member of the returned list. - Finally, save the results in the database.
Ready to delve into the details? Let’s go!
Set Node

Start by using the Set node to initialize your search prompt. This practice makes your input/reusable variables easy to change and maintain. Alternatively, you can utilize an incoming Webhook node or call this workflow from a parent one.
Set Node configuration:
- Add a new “String” Value.
- Ensure its
Nameissearch_value. - Input
Javascript developer.
Telegram CoPilot: Search Public Chats Node

There are two main actions for searching in Telegram: searchPublicChat and searchPublicChats.
The former requires a username and returns the ID of a channel, group, or user,
while the latter accepts any string and attempts to match it with a username, title, and description.
We’ll be using the latter.
To set up the node, input the search_query from the Set Node into the Query field.
Your configuration should look like this: {{ $node["Set: search_query"].json["search_query"] }}.
Code Node for JSON Mapping

The Code Node is essential for data transformation. The previous node returns a JSON like this:
[{"_": "chats",
"total_count": 10,
"chat_ids": [ -1111469926810, -1121234788613 ]}]
To make it work for us, we need to bring chat_ids one level up, enabling us to iterate over the values in the chat_ids array.
If we don’t do this, all downstream nodes will only be executed once, limiting our ability to get details about all chats.
Split in Batches Node

We will use Split in Batches to loop through the data.
Make sure to specify a Batch Size of 1 to process every entry.
Important: The Split in Batches node requires a feedback connection. When your workflow is ready, connect the output of your last node with the input of the “Split in Batches” node to initiate the iterations.
Telegram CoPilot: Get Chat Information

The Telegram CoPilot: Get Chat node fetches information about a Telegram chat based on its ID.
We will use it to retrieve details for every chat_id received from the SearchPublicChats node.
Input the following configuration:
Chat IDshould use the following Expression to read value from the previous step in a loop:{{ $json.chat_id }}.
MongoDB Insert Node

The MongoDB Insert node captures and stores your search results in your MongoDB database. You’ll need to specify the JSON keys that you’d like to write into the database.
Set up the MongoDB Insert node to store all fields in the database by:
- Specifying
searchas the collection name where all the data will be stored in theCollectionfield. - Including all keys by inputting the following expression into the
Fieldsfield:{{ Object.keys($json).join(",") }}.
Time to Test
Execute your workflow and then check your MongoDB database! You’ll now find your search results saved and ready for your automation tasks!
Wrapping up
And that’s it! You have now successfully configured a TelePilot search workflow using n8n. This powerful tool allows you to easily search through Telegram channels, groups, or users and efficiently store your search results in MongoDB for future automation tasks.
If you run into any issues or if you have any questions, we’re here to help. Join our growing community over on Telegram: https://t.me/telepilotco Here we regularly share tips, tricks, and updates on everything TelePilot.
We hope this tutorial was helpful and has inspired you to explore the other powerful features that TelePilot has to offer. Stay tuned for more tutorials and don’t forget to share your own creative workflows in our Telegram group. Happy automating!