Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion genie_bot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import argparse
from config.config_env import create_config_env
from handlers.conversation import conversation_handler_question
from handlers.conversation import conversation_handler_question,getting_api_details
from handlers.handlers import *
from telegram.ext import ApplicationBuilder, CommandHandler, CallbackQueryHandler
import os
Expand Down Expand Up @@ -29,6 +29,7 @@ def main():
application.add_handler(CommandHandler("help", help_command))
application.add_handler(CommandHandler("ip", get_public_ip_command))
application.add_handler(CommandHandler('api', api_command))
application.add_handler(getting_api_details())
application.add_handler(conversation_handler_question())
application.add_handler(CallbackQueryHandler(button))

Expand Down
13 changes: 13 additions & 0 deletions handlers/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,16 @@ def conversation_handler_question():
fallbacks=[CommandHandler("cancel", cancel_conversation)],
)
return conv_handler

def getting_api_details():
conv_handler = ConversationHandler(
entry_points=[CommandHandler('create', create_challenge)],
states={
ASK_FOR_API_ID: [MessageHandler(filters.TEXT & ~filters.COMMAND, get_api_id)],
ASK_FOR_API_HASH: [MessageHandler(filters.TEXT & ~filters.COMMAND, get_api_hash)],
ASK_FOR_PHONE_NUMBER: [MessageHandler(filters.TEXT & ~filters.COMMAND, get_phone_number)],
},
fallbacks=[CommandHandler('cancel', cancel_conversation)],
)
return conv_handler

43 changes: 42 additions & 1 deletion handlers/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
from telegram import Update, KeyboardButton, ReplyKeyboardMarkup, InlineKeyboardMarkup
from telegram.ext import ContextTypes, CallbackContext, ConversationHandler
import requests
from telethon import TelegramClient, events,functions,types
from config import CONSTANTS
from config.CONSTANTS import DIFFICULTY_LIST

ASK_FOR_TOPIC, ASK_FOR_DIFF, ASK_FOR_NUM_ANS = range(3)

ASK_FOR_API_HASH, ASK_FOR_PHONE_NUMBER, ASK_FOR_API_ID = range(3)

def get_diff_keyboard():
buttons = [KeyboardButton(diff) for diff in DIFFICULTY_LIST]
Expand Down Expand Up @@ -151,3 +152,43 @@ async def button(update: Update, context: CallbackContext) -> None:
await query.edit_message_text(text=f"Selected option: {response_data['Answer'][int(selected_answer)]}\n\n{feedback_with_explanation}")
return






async def create_challenge(update: Update, context: CallbackContext) -> int:
await update.message.reply_text("Please provide your API_ID:")
return ASK_FOR_API_ID

async def get_api_id(update: Update, context: CallbackContext) -> str:
context.user_data['API_ID'] = update.message.text
await update.message.reply_text("Thanks! Now, what's your API_HASH?")
return ASK_FOR_API_HASH

async def get_api_hash(update: Update, context: CallbackContext) -> str:
context.user_data['API_HASH'] = update.message.text
await update.message.reply_text("Great! Finally, what is your phone number?")
return ASK_FOR_PHONE_NUMBER

async def get_phone_number(update: Update, context: CallbackContext) -> str:
context.user_data['PHONE_NUMBER'] = update.message.text
user_data = context.user_data
await connect_to_telegram_API(update, context)
return ConversationHandler.END





async def connect_to_telegram_API(update: Update, context: CallbackContext) -> None:

api_id= int(context.user_data['API_ID'])
api_hash= context.user_data['API_HASH']
phone= context.user_data['PHONE_NUMBER']
try:
client = TelegramClient('user_session13', str(api_id), str(api_hash))
await client.start(phone)
await update.message.reply_text("hi you are now connected to telegram api")
except Exception as e:
await update.message.reply_text(f"An unexpected error occurred: {str(e)}")
Binary file added user_session13.session
Binary file not shown.