I’m developing a Telegram bot using Python, which connects to a Google Sheet to display data from a couple of different worksheets. Unfortunately, when executing the code, I encounter a TypeError that states Updater.__init__() is missing a required argument called update_queue. Here’s the code I’m working on:
# Bot implementation
import telegram
from telegram import InlineKeyboardMarkup, InlineKeyboardButton
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler
from google.oauth2 import service_account
import gspread
# Bot token
BOT_TOKEN = 'your_bot_token_here'
# Google API settings
API_SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
CREDS_FILE = 'path/to/your/credentials.json'
document_id = 'your_spreadsheet_id'
# Setup Google Sheets authentication
credentials = service_account.Credentials.from_service_account_file(CREDS_FILE, scopes=API_SCOPES)
# Function to retrieve worksheet data
def fetch_worksheet_data(worksheet_name):
client = gspread.authorize(credentials)
spreadsheet = client.open_by_key(document_id)
target_sheet = spreadsheet.worksheet(worksheet_name)
return target_sheet.get_all_values()
# Handler for /start command
def handle_start(bot, update):
buttons = [[InlineKeyboardButton("Reports", callback_data='reports')],
[InlineKeyboardButton("Metrics", callback_data='metrics')]]
markup = InlineKeyboardMarkup(buttons)
update.message.reply_text('Select an option:', reply_markup=markup)
# Handler for button clicks
def handle_button_click(bot, update):
query = update.callback_query
selected_sheet = query.data
sheet_data = fetch_worksheet_data(selected_sheet)
formatted_data = '\n'.join(['\t'.join(row) for row in sheet_data])
query.edit_message_text(text=formatted_data)
def run_bot():
bot_updater = Updater(BOT_TOKEN)
dispatcher = bot_updater.dispatcher
dispatcher.add_handler(CommandHandler("start", handle_start))
dispatcher.add_handler(CallbackQueryHandler(handle_button_click))
bot_updater.start_polling()
bot_updater.idle()
if __name__ == '__main__':
run_bot()
The intention is for the bot to provide two buttons that upon being clicked will display the corresponding Google Sheet data, but I’m facing issues with this Updater error. Can anyone help me out?