File size: 1,518 Bytes
0b43703
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import telebot
from Summarizer import *


# Define a function to process the YouTube URL and generate a summary
def process_youtube_url(url):
    try:
        # Use the 'process' function from your summarizer module
        summary = process(url)
        return summary
    except Exception as e:
        # Handle any errors that may occur during processing
        return f"Error processing YouTube URL: {e}"


# Set up the Telegram Bot
def main():
    # Retrieve the Telegram bot token from environment variables
    telegram_bot_token = os.getenv('TELEGRAM_BOT_TOKEN', 'YOUR_TELEGRAM_BOT_TOKEN')
    bot = telebot.TeleBot(telegram_bot_token)

    # Define a function to handle the user's input  (e.g., the YouTube URL)
    def url_handler(message):
        # Get the user's input
        url = message.text
        print(f"Received YouTube URL: {url}")

        # Process the YouTube URL and generate a summary
        summary = process_youtube_url(url)

        # Send the summary back to the user
        bot.send_message(message.chat.id, summary, parse_mode="Markdown")

    @bot.message_handler(commands=['summarize'])
    def message_handler(message):
        text = "Please enter the URL of the YouTube video you would like to summarize."
        sent_msg = bot.send_message(message.chat.id, text, parse_mode="Markdown")
        bot.register_next_step_handler(sent_msg, url_handler)

    # Start the bot
    bot.infinity_polling()


# Entry point of the script
if __name__ == '__main__':
    main()