Skip to content

Commit

Permalink
Implement a basic bot template
Browse files Browse the repository at this point in the history
Add the gitignore entries for session files as well as create an example env file for reference.
  • Loading branch information
pranayadmn authored Mar 18, 2024
1 parent c2a8256 commit 07200d8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
API_ID=12345
API_HASH=0123456789abcdef0123456789abcdef
BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,7 @@ pyrightconfig.json
# Ignore all local history of files
.history
.ionide

### Telethon ###
*.session
*.session-journal
18 changes: 18 additions & 0 deletions src/Bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from dotenv import load_dotenv
from telethon import TelegramClient, events
from os import getenv

def main() -> None:
load_dotenv()

api_id = getenv("API_ID")
api_hash = getenv("API_HASH")
bot_token = getenv("BOT_TOKEN")

app = TelegramClient('app', api_id, api_hash).start(bot_token=bot_token)

@app.on(events.NewMessage(incoming=True, pattern='/start'))
async def start(event):
await event.reply("Hello!")

app.run_until_disconnected()
4 changes: 4 additions & 0 deletions src/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from Bot import main

if __name__ == "__main__":
main()

0 comments on commit 07200d8

Please sign in to comment.