File size: 1,537 Bytes
1c6621e
77d5031
c35f8ff
029eb02
1c6621e
c35f8ff
 
029eb02
 
c35f8ff
 
029eb02
 
c35f8ff
77d5031
1c6621e
77d5031
 
 
 
 
c35f8ff
029eb02
77d5031
 
029eb02
 
c35f8ff
77d5031
 
 
 
1c6621e
 
 
 
 
 
 
 
 
77d5031
1c6621e
c35f8ff
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
import threading
import asyncio
from telegram import Update
from telegram.ext import Application, CommandHandler, CallbackContext
import time

# Function to start the bot and reply with a welcome message
async def start(update: Update, context: CallbackContext) -> None:
    await update.message.reply_text('Hello! I am your bot. How can I help you today?')

# Function to handle the /help command
async def help_command(update: Update, context: CallbackContext) -> None:
    await update.message.reply_text('Use /start to get started with the bot.')

# Function to run the bot
def run_bot():
    # Create a new asyncio event loop
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)

    # Define your bot token
    token = '7714605375:AAEfd-D1Y1np-HBJ0jOR1vGfyNJD2hloPAc'
    application = Application.builder().token(token).build()

    # Add command handlers
    application.add_handler(CommandHandler("start", start))
    application.add_handler(CommandHandler("help", help_command))

    # Start polling for updates
    loop.run_until_complete(application.run_polling())

# Main function to start the bot in a separate thread
def main():
    # Start the bot in a separate thread
    bot_thread = threading.Thread(target=run_bot)
    bot_thread.start()

    # Now, you can start your web server or any other service that should run concurrently
    print("Server is running...")
    while True:
        time.sleep(1)  # Replace with actual server logic (e.g., web server loop)

if __name__ == "__main__":
    main()