├── .idea ├── .gitignore ├── Message-Search-Bot.iml ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── jsonSchemas.xml ├── misc.xml └── modules.xml ├── .replit ├── Procfile ├── README.md ├── app.json ├── configs.py ├── main.py └── requirements.txt /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/Message-Search-Bot.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 47 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/jsonSchemas.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.replit: -------------------------------------------------------------------------------- 1 | language = "bash" 2 | run = "pip3 install -r requirements.txt; python3 main.py" -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | worker: python3 main.py -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Message-Search-Bot 2 | A Telegram Bot for searching any channel messages from Inline by [@AbirHasan2005](https://github.com/AbirHasan2005). 3 | 4 | I made this for [@AHListBot](https://t.me/AHListBot). You can use this for something else. Edit according to your use. 5 | 6 | We have to use Bot for Inline Search & Userbot for Searching in Channels. So both Bot & Userbot will work together. 7 | 8 | ## Deploy to Heroku: 9 | [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/AbirHasan2005/Message-Search-Bot) 10 | 11 | ### Support Group: 12 | 13 | 14 | ### Follow on: 15 |

16 | 17 |

18 |

19 | 20 |

21 |

22 | 23 |

24 |

25 | 26 |

27 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "This is Inline Channel Messages Search Bot by @AbirHasan2005", 3 | "description": "This is Inline Channel Messages Search Bot by @AbirHasan2005in Pyrogram by @AbirHasan2005", 4 | "keywords": [ 5 | "telegram", 6 | "channel", 7 | "messages", 8 | "search", 9 | "bot" 10 | ], 11 | "repository": "https://github.com/AbirHasan2005/Message-Search-Bot", 12 | "website": "https://telegram.dog/AbirHasan2005", 13 | "success_url": "https://t.me/AHListBot", 14 | "env": { 15 | "API_ID": { 16 | "description": "Get this value from my.telegram.org or @TeleORG_Bot" 17 | }, 18 | "API_HASH": { 19 | "description": "Get this value from my.telegram.org or @TeleORG_Bot" 20 | }, 21 | "USER_SESSION_STRING": { 22 | "description": "Get this from @StringSessionGen_Bot" 23 | }, 24 | "BOT_SESSION_NAME": { 25 | "description": "Any Session Name for Bot." 26 | }, 27 | "BOT_TOKEN": { 28 | "description": "Get this from @BotFather" 29 | }, 30 | "CHANNEL_ID": { 31 | "description": "Channel ID for Searching Messages." 32 | } 33 | }, 34 | "buildpacks": [ 35 | { 36 | "url": "heroku/python" 37 | } 38 | ], 39 | "formation": { 40 | "worker": { 41 | "quantity": 1, 42 | "size": "free" 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /configs.py: -------------------------------------------------------------------------------- 1 | # (c) @AbirHasan2005 2 | 3 | import os 4 | 5 | 6 | class Config(object): 7 | API_ID = int(os.environ.get("API_ID", 12345)) 8 | API_HASH = os.environ.get("API_HASH", "") 9 | BOT_TOKEN = os.environ.get("BOT_TOKEN", "") 10 | BOT_SESSION_NAME = os.environ.get("BOT_SESSION_NAME", "Messages-Search-Bot") 11 | USER_SESSION_STRING = os.environ.get("USER_SESSION_STRING", "") 12 | CHANNEL_ID = int(os.environ.get("CHANNEL_ID", -100)) 13 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | # (c) @AbirHasan2005 2 | # I just made this for searching a channel message from inline. 3 | # Maybe you can use this for something else. 4 | # I first made this for @AHListBot ... 5 | # Edit according to your use. 6 | 7 | from configs import Config 8 | from pyrogram import Client, filters, idle 9 | from pyrogram.errors import QueryIdInvalid 10 | from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, InlineQuery, InlineQueryResultArticle, \ 11 | InputTextMessageContent 12 | 13 | # Bot Client for Inline Search 14 | Bot = Client( 15 | session_name=Config.BOT_SESSION_NAME, 16 | api_id=Config.API_ID, 17 | api_hash=Config.API_HASH, 18 | bot_token=Config.BOT_TOKEN 19 | ) 20 | # User Client for Searching in Channel. 21 | User = Client( 22 | session_name=Config.USER_SESSION_STRING, 23 | api_id=Config.API_ID, 24 | api_hash=Config.API_HASH 25 | ) 26 | 27 | 28 | @Bot.on_message(filters.private & filters.command("start")) 29 | async def start_handler(_, event: Message): 30 | await event.reply_text( 31 | "Hi, I am Messages Search Bot!\n\n" 32 | "**Developer:** @AbirHasan2005\n" 33 | "**Demo Bot:** @AHListBot", 34 | reply_markup=InlineKeyboardMarkup([ 35 | [InlineKeyboardButton("Support Group", url="https://t.me/DevsZone"), 36 | InlineKeyboardButton("Bots Channel", url="https://t.me/Discovery_Updates")], 37 | [InlineKeyboardButton("Developer - @AbirHasan2005")], 38 | [InlineKeyboardButton("Search Inline", switch_inline_query_current_chat=""), InlineKeyboardButton("Go Inline", switch_inline_query="")] 39 | ]) 40 | ) 41 | 42 | 43 | @Bot.on_inline_query() 44 | async def inline_handlers(_, event: InlineQuery): 45 | answers = list() 46 | # If Search Query is Empty 47 | if event.query == "": 48 | answers.append( 49 | InlineQueryResultArticle( 50 | title="This is Inline Messages Search Bot!", 51 | description="You can search Channel All Messages using this bot.", 52 | input_message_content=InputTextMessageContent( 53 | message_text="Using this Bot you can Search a Channel All Messages using this bot.\n\n" 54 | "Made by @AbirHasan2005", 55 | disable_web_page_preview=True 56 | ), 57 | reply_markup=InlineKeyboardMarkup([ 58 | [InlineKeyboardButton("Search Here", switch_inline_query_current_chat="")], 59 | [InlineKeyboardButton("Support Group", url="https://t.me/DevsZone"), 60 | InlineKeyboardButton("Bots Channel", url="https://t.me/Discovery_Updates")], 61 | [InlineKeyboardButton("Developer - @AbirHasan2005", url="https://t.me/AbirHasan2005")] 62 | ]) 63 | ) 64 | ) 65 | # Search Channel Message using Search Query Words 66 | else: 67 | async for message in User.search_messages(chat_id=Config.CHANNEL_ID, limit=50, query=event.query): 68 | if message.text: 69 | answers.append(InlineQueryResultArticle( 70 | title="{}".format(message.text.split("\n", 1)[0]), 71 | description="{}".format(message.text.rsplit("\n", 1)[-1]), 72 | reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Search Again", switch_inline_query_current_chat="")]]), 73 | input_message_content=InputTextMessageContent( 74 | message_text=message.text.markdown, 75 | parse_mode="markdown", 76 | disable_web_page_preview=True 77 | ) 78 | )) 79 | try: 80 | await event.answer( 81 | results=answers, 82 | cache_time=0 83 | ) 84 | print(f"[{Config.BOT_SESSION_NAME}] - Answered Successfully - {event.from_user.first_name}") 85 | except QueryIdInvalid: 86 | print(f"[{Config.BOT_SESSION_NAME}] - Failed to Answer - {event.from_user.first_name}") 87 | 88 | # Start Clients 89 | Bot.start() 90 | User.start() 91 | # Loop Clients till Disconnects 92 | idle() 93 | # After Disconnects, 94 | # Stop Clients 95 | Bot.stop() 96 | User.stop() 97 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pyrogram==1.4.16 2 | TgCrypto 3 | --------------------------------------------------------------------------------