I am currently working on a Telegram bot that takes a channel ID as input and should return the channel details. However, when I enter a channel ID on Telegram, nothing happens. I am using ngrok on port 5000 for local development. Here's the code I have so far:
import loggingfrom flask import Flask, requestfrom telegram import Botfrom googleapiclient.discovery import buildapp = Flask(__name__)# Set up logginglogging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.DEBUG)logger = logging.getLogger(__name__)# Define the route for the Telegram webhook@app.route('/YvaBot', methods=['POST'])def telegram_webhook(): update = request.get_json() if 'message' in update: process_message(update['message']) return 'OK'# Create a function to process incoming messagesdef process_message(message): chat_id = message['chat']['id'] if 'text' in message: channel_id = message['text'] channel_details = get_channel_details(channel_id) send_message(chat_id, channel_details)# Create a function to get channel details using the YouTube APIdef get_channel_details(channel_id): # Set up the YouTube API client api_service_name = 'youtube' api_version = 'v3' developer_key = 'DEVELOPER_KEY' youtube = build(api_service_name, api_version, developerKey=developer_key) # Retrieve channel details request = youtube.channels().list( part='snippet,statistics', id=channel_id ) response = request.execute() # Parse the response and extract relevant details channel = response['items'][0] title = channel['snippet']['title'] description = channel['snippet']['description'] subscriber_count = channel['statistics']['subscriberCount'] # Create a formatted string with the channel details channel_details = f"Channel: {title}\nDescription: {description}\nSubscribers: {subscriber_count}" return channel_details# Create a function to send messages to the userdef send_message(chat_id, text): bot = Bot(token='BOT_TOKEN') bot.send_message(chat_id=chat_id, text=text)# Start the Flask development serverif __name__ == '__main__': app.run(port=5000)
I have ensured that I have the correct developer key and bot token in the code. However, when I enter a channel ID on Telegram, the bot does not return any channel details. I would appreciate any assistance in identifying the issue and resolving it. Thank you in advance!