├── runtime.txt
├── Procfile
├── requirements.txt
├── env.sample
├── .gitignore
├── creds.py
├── README.md
├── app.json
├── LICENSE
└── main.py
/runtime.txt:
--------------------------------------------------------------------------------
1 | python-3.9.2
--------------------------------------------------------------------------------
/Procfile:
--------------------------------------------------------------------------------
1 | worker: python3 main.py
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | pyrogram==1.2.9
2 | telegraph==1.4.1
3 | tgcrypto==1.2.2
4 | python-dotenv==0.17.1
--------------------------------------------------------------------------------
/env.sample:
--------------------------------------------------------------------------------
1 | BOT_TOKEN = "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
2 | API_ID = 12345
3 | API_HASH = "0123456789abcdef0123456789abcdef"
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Personal files
2 | *.session
3 | *.ini
4 | *.session-journal
5 | *.env
6 |
7 | # compile time caches and files
8 | __pycache__/
9 | downloads/
--------------------------------------------------------------------------------
/creds.py:
--------------------------------------------------------------------------------
1 | import os
2 | from dotenv import load_dotenv, find_dotenv
3 |
4 | load_dotenv(find_dotenv())
5 |
6 |
7 | class Credentials:
8 | BOT_TOKEN = os.getenv("BOT_TOKEN") # from @botfather
9 | API_ID = int(os.getenv("API_ID")) # from https://my.telegram.org/apps
10 | API_HASH = os.getenv("API_HASH") # from https://my.telegram.org/apps
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Image-UploadBot
2 |
3 | > A simplest telegram to telegra.ph image uploader bot
4 |
5 | ## installation (easy way)
6 |
7 | [](https://heroku.com/deploy?template=https://github.com/CW4RR10R/Image-UploadBot/tree/master)
8 |
9 | Libraries used: => Pyrogram => Telegraph
10 |
11 | Join [@cwprojects](https://t.me/cwprojects)
12 |
--------------------------------------------------------------------------------
/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Image upload bot",
3 | "description": "A bot to upload telegram images to telegraph",
4 | "repository": "https://github.com/CW4RR10R/Image-UploadBot",
5 | "logo": "https://telegra.ph/file/33adaf8d6c398edf81967.jpg",
6 | "keywords": ["telegram", "telegraph", "imageuploader","telegram bot"],
7 | "env": {
8 | "BOT_TOKEN": {
9 | "description": "Your Bot token from @Botfather"
10 | },
11 | "API_ID": {
12 | "description": "Your API_ID from https://my.telegram.org/apps "
13 | },
14 | "API_HASH": {
15 | "description": "Your API_HASH from https://my.telegram.org/apps"
16 | }
17 | },
18 | "buildpacks": [
19 | {
20 | "url": "heroku/python"
21 | }
22 | ]
23 | }
24 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 W4RR10R
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 logging
3 | from pyrogram import Client, filters
4 | from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
5 | from creds import Credentials
6 | from telegraph import upload_file
7 |
8 | logging.basicConfig(level=logging.WARNING)
9 |
10 |
11 | tgraph = Client(
12 | "Image upload bot",
13 | bot_token=Credentials.BOT_TOKEN,
14 | api_id=Credentials.API_ID,
15 | api_hash=Credentials.API_HASH
16 | )
17 |
18 |
19 | @tgraph.on_message(filters.command("start"))
20 | async def start(client, message):
21 | await message.reply_text(
22 | text=f"Hello {message.from_user.mention},\nI'm a telegram to telegra.ph image uploader bot by @W4RR10R",
23 | disable_web_page_preview=True
24 | )
25 |
26 |
27 | @tgraph.on_message(filters.photo)
28 | async def getimage(client, message):
29 | dwn = await message.reply_text("Downloading to my server...", True)
30 | img_path = await message.download()
31 | await dwn.edit_text("Uploading as telegra.ph link...")
32 | try:
33 | url_path = upload_file(img_path)[0]
34 | except Exception as error:
35 | await dwn.edit_text(f"Oops something went wrong\n{error}")
36 | return
37 | await dwn.edit_text(
38 | text=f"Link :- https://telegra.ph{url_path}",
39 | disable_web_page_preview=True,
40 | reply_markup=InlineKeyboardMarkup(
41 | [
42 | [
43 | InlineKeyboardButton(
44 | text="Open Link", url=f"https://telegra.ph{url_path}"
45 | ),
46 | InlineKeyboardButton(
47 | text="Share Link",
48 | url=f"https://telegram.me/share/url?url=https://telegra.ph{url_path}",
49 | )
50 | ]
51 | ]
52 | )
53 | )
54 | os.remove(img_path)
55 |
56 |
57 | tgraph.run()
58 |
--------------------------------------------------------------------------------