├── Procfile ├── requirements.txt ├── .gitignore ├── README.md ├── LICENSE └── main.py /Procfile: -------------------------------------------------------------------------------- 1 | worker: python3 main.py 2 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pyrogram 2 | tgcrypto 3 | aiofiles 4 | python-dotenv 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/__pycache__ 2 | **/venv 3 | *.session 4 | *.pyc 5 | *.env 6 | test.py 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pyrogram Json Bot 2 | A telegram to response json bot 3 | 4 | --- 5 | 6 | ## Variables 7 | 8 | - `API_HASH` Your API Hash from my.telegram.org 9 | - `API_ID` Your API ID from my.telegram.org 10 | - `BOT_TOKEN` Your bot token from @BotFather 11 | 12 | --- 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Fayas 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import os 2 | import dotenv 3 | from io import BytesIO 4 | from pyrogram import Client, filters 5 | from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton 6 | 7 | 8 | dotenv.load_dotenv() 9 | 10 | Bot = Client( 11 | "Pyrogram Json Bot", 12 | bot_token = os.environ.get("BOT_TOKEN"), 13 | api_id = int(os.environ.get("API_ID")), 14 | api_hash = os.environ.get("API_HASH") 15 | ) 16 | 17 | START_TEXT = """Hello {}, 18 | I am a telegram to pyrogram json bot. I can send details json of a message. 19 | 20 | Made by @FayasNoushad""" 21 | 22 | HELP_TEXT = """**More Help** 23 | 24 | - Just send any type of message for json details 25 | - Add me to group and send any type of message in group and reply /json for json details of message 26 | 27 | Made by @FayasNoushad""" 28 | 29 | ABOUT_TEXT = """**About Me** 30 | 31 | - **Bot :** `Pyrogram Json Bot` 32 | - **Developer :** [GitHub](https://github.com/FayasNoushad) | [Telegram](https://telegram.me/FayasNoushad) 33 | - **Source :** [Click here](https://github.com/FayasNoushad/Pyrogram-Json-Bot) 34 | - **Language :** [Python3](https://python.org) 35 | - **Framework :** [Pyrogram](https://pyrogram.org)""" 36 | 37 | START_BUTTONS = InlineKeyboardMarkup( 38 | [ 39 | [ 40 | InlineKeyboardButton('Send Feedback', url='https://telegram.me/FayasNoushad') 41 | ], 42 | [ 43 | InlineKeyboardButton('Help', callback_data='help'), 44 | InlineKeyboardButton('About', callback_data='about'), 45 | InlineKeyboardButton('Close', callback_data='close') 46 | ] 47 | ] 48 | ) 49 | 50 | HELP_BUTTONS = InlineKeyboardMarkup( 51 | [ 52 | [ 53 | InlineKeyboardButton('Home', callback_data='home'), 54 | InlineKeyboardButton('About', callback_data='about'), 55 | InlineKeyboardButton('Close', callback_data='close') 56 | ] 57 | ] 58 | ) 59 | 60 | ABOUT_BUTTONS = InlineKeyboardMarkup( 61 | [ 62 | [ 63 | InlineKeyboardButton('Home', callback_data='home'), 64 | InlineKeyboardButton('Help', callback_data='help'), 65 | InlineKeyboardButton('Close', callback_data='close') 66 | ] 67 | ] 68 | ) 69 | 70 | JSON_BUTTON = InlineKeyboardMarkup( 71 | [ 72 | [ 73 | InlineKeyboardButton('⚙ Send Feedback ⚙', url='https://telegram.me/FayasNoushad') 74 | ] 75 | ] 76 | ) 77 | 78 | 79 | @Bot.on_callback_query() 80 | async def cb_handler(bot, update): 81 | if update.data == "home": 82 | await update.message.edit_text( 83 | text=START_TEXT.format(update.from_user.mention), 84 | reply_markup=START_BUTTONS, 85 | disable_web_page_preview=True 86 | ) 87 | elif update.data == "help": 88 | await update.message.edit_text( 89 | text=HELP_TEXT, 90 | reply_markup=HELP_BUTTONS, 91 | disable_web_page_preview=True 92 | ) 93 | elif update.data == "about": 94 | await update.message.edit_text( 95 | text=ABOUT_TEXT, 96 | reply_markup=ABOUT_BUTTONS, 97 | disable_web_page_preview=True 98 | ) 99 | else: 100 | await update.message.delete() 101 | 102 | 103 | @Bot.on_message(filters.private & filters.command(["start"])) 104 | async def start(bot, update): 105 | await update.reply_text( 106 | text=START_TEXT.format(update.from_user.mention), 107 | disable_web_page_preview=True, 108 | reply_markup=START_BUTTONS 109 | ) 110 | 111 | 112 | @Bot.on_message(filters.private & filters.command(["help"])) 113 | async def help(bot, update): 114 | await update.reply_text( 115 | text=HELP_TEXT, 116 | disable_web_page_preview=True, 117 | reply_markup=HELP_BUTTONS 118 | ) 119 | 120 | 121 | @Bot.on_message(filters.private & filters.command(["about"])) 122 | async def about(bot, update): 123 | await update.reply_text( 124 | text=ABOUT_TEXT, 125 | disable_web_page_preview=True, 126 | reply_markup=ABOUT_BUTTONS 127 | ) 128 | 129 | 130 | @Bot.on_edited_message(filters.private & (filters.text | filters.media | filters.service)) 131 | @Bot.on_message(filters.private & ( 132 | filters.text | filters.media | filters.service) & filters.reply) 133 | @Bot.on_message(filters.private & (filters.text | filters.media | filters.service)) 134 | async def private(bot, update): 135 | if update.text == "/json": 136 | await group(bot, update) 137 | return 138 | await reply_file(bot, update) 139 | 140 | 141 | @Bot.on_message(filters.group & filters.command(["json"])) 142 | async def group(bot, update): 143 | await reply_file(bot, update.reply_to_message) 144 | 145 | 146 | async def reply_file(bot, update): 147 | with BytesIO(str.encode(str(update))) as file: 148 | file.name = "json.txt" 149 | await update.reply_document( 150 | document=file, 151 | quote=True, 152 | reply_markup=JSON_BUTTON 153 | ) 154 | try: 155 | os.remove(file) 156 | except: 157 | pass 158 | 159 | 160 | @Bot.on_inline_query() 161 | async def inline(bot, update): 162 | await update.answer( 163 | results=[], 164 | switch_pm_text="Your json was sent to pm", 165 | switch_pm_parameter="start" 166 | ) 167 | with BytesIO(str.encode(str(update))) as file: 168 | file.name = "json.txt" 169 | await bot.send_document( 170 | chat_id=update.from_user.id, 171 | document=file, 172 | reply_markup=JSON_BUTTON 173 | ) 174 | try: 175 | os.remove(file) 176 | except: 177 | pass 178 | 179 | 180 | Bot.run() 181 | --------------------------------------------------------------------------------