-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
60 lines (45 loc) · 1.89 KB
/
main.py
File metadata and controls
60 lines (45 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
main.py — entry point for DeepakReachesBot (Telegram).
Run:
python main.py
"""
import logging
from telegram.ext import Application
import config
from bot.handlers.email_handler import build_email_conversation, STANDALONE_HANDLERS
from bot.handlers.batch_handler import BATCH_HANDLERS
from bot.handlers.settings_handler import SETTINGS_HANDLERS
logging.basicConfig(
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
level=logging.INFO,
)
logger = logging.getLogger(__name__)
async def post_init(application: Application) -> None:
from telegram import BotCommand
commands = [
BotCommand("email", "Compose & send an outreach email"),
BotCommand("batch_email", "Upload a CSV to send emails in bulk"),
BotCommand("provider", "Switch between Gemini, OpenAI, and OpenRouter"),
BotCommand("setkey", "Set your own API key (/setkey <provider> <key>)"),
BotCommand("health", "Check if the bot is online"),
BotCommand("cancel", "Cancel your current action"),
BotCommand("commands", "Show the list of commands"),
BotCommand("help", "Show help message"),
]
await application.bot.set_my_commands(commands)
logger.info("Bot commands registered to Telegram Menu.")
def main() -> None:
logger.info("Starting DeepakReachesBot…")
app = Application.builder().token(config.TELEGRAM_BOT_TOKEN).post_init(post_init).build()
# Register conversation handler (must come before standalone /cancel)
app.add_handler(build_email_conversation())
for handler in STANDALONE_HANDLERS:
app.add_handler(handler)
for handler in SETTINGS_HANDLERS:
app.add_handler(handler)
for handler in BATCH_HANDLERS:
app.add_handler(handler)
logger.info("Bot is polling. Press Ctrl+C to stop.")
app.run_polling(allowed_updates=["message", "callback_query"])
if __name__ == "__main__":
main()