Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import threading
|
|
|
|
| 2 |
from telegram import Update
|
| 3 |
from telegram.ext import Application, CommandHandler, CallbackContext
|
| 4 |
import time
|
|
@@ -11,26 +12,33 @@ async def start(update: Update, context: CallbackContext) -> None:
|
|
| 11 |
async def help_command(update: Update, context: CallbackContext) -> None:
|
| 12 |
await update.message.reply_text('Use /start to get started with the bot.')
|
| 13 |
|
| 14 |
-
#
|
| 15 |
def run_bot():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
token = '7714605375:AAEfd-D1Y1np-HBJ0jOR1vGfyNJD2hloPAc'
|
| 17 |
application = Application.builder().token(token).build()
|
| 18 |
-
|
|
|
|
| 19 |
application.add_handler(CommandHandler("start", start))
|
| 20 |
application.add_handler(CommandHandler("help", help_command))
|
| 21 |
-
|
| 22 |
-
application.run_polling()
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
def main():
|
| 25 |
# Start the bot in a separate thread
|
| 26 |
bot_thread = threading.Thread(target=run_bot)
|
| 27 |
bot_thread.start()
|
| 28 |
|
| 29 |
# Now, you can start your web server or any other service that should run concurrently
|
| 30 |
-
# Example: Running a basic server or any other task.
|
| 31 |
print("Server is running...")
|
| 32 |
while True:
|
| 33 |
time.sleep(1) # Replace with actual server logic (e.g., web server loop)
|
| 34 |
-
|
| 35 |
if __name__ == "__main__":
|
| 36 |
main()
|
|
|
|
| 1 |
import threading
|
| 2 |
+
import asyncio
|
| 3 |
from telegram import Update
|
| 4 |
from telegram.ext import Application, CommandHandler, CallbackContext
|
| 5 |
import time
|
|
|
|
| 12 |
async def help_command(update: Update, context: CallbackContext) -> None:
|
| 13 |
await update.message.reply_text('Use /start to get started with the bot.')
|
| 14 |
|
| 15 |
+
# Function to run the bot
|
| 16 |
def run_bot():
|
| 17 |
+
# Create a new asyncio event loop
|
| 18 |
+
loop = asyncio.new_event_loop()
|
| 19 |
+
asyncio.set_event_loop(loop)
|
| 20 |
+
|
| 21 |
+
# Define your bot token
|
| 22 |
token = '7714605375:AAEfd-D1Y1np-HBJ0jOR1vGfyNJD2hloPAc'
|
| 23 |
application = Application.builder().token(token).build()
|
| 24 |
+
|
| 25 |
+
# Add command handlers
|
| 26 |
application.add_handler(CommandHandler("start", start))
|
| 27 |
application.add_handler(CommandHandler("help", help_command))
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
# Start polling for updates
|
| 30 |
+
loop.run_until_complete(application.run_polling())
|
| 31 |
+
|
| 32 |
+
# Main function to start the bot in a separate thread
|
| 33 |
def main():
|
| 34 |
# Start the bot in a separate thread
|
| 35 |
bot_thread = threading.Thread(target=run_bot)
|
| 36 |
bot_thread.start()
|
| 37 |
|
| 38 |
# Now, you can start your web server or any other service that should run concurrently
|
|
|
|
| 39 |
print("Server is running...")
|
| 40 |
while True:
|
| 41 |
time.sleep(1) # Replace with actual server logic (e.g., web server loop)
|
| 42 |
+
|
| 43 |
if __name__ == "__main__":
|
| 44 |
main()
|