I’m attempting to develop a Python-based Telegram bot that connects to Google Sheets to display data from two specific sheets on demand. The bot is designed to have two buttons: one for viewing the “dashboard” and the other for the “KPI”. However, I’m facing an error when I run my code:
Traceback (most recent call last):
File "C:\Users\ASUS\Downloads\philbot.py", line 51, in <module>
main()
File "C:\Users\ASUS\Downloads\philbot.py", line 41, in main
updater = Updater(TOKEN)
^^^^^^^^^^^^^^
TypeError: Updater.__init__() missing 1 required positional argument: 'update_queue'
Below is my existing code:
import telegram
from telegram import InlineKeyboardMarkup, InlineKeyboardButton
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler
from google.oauth2 import service_account
import gspread
# Telegram bot token
TOKEN = 'xxxxxyyyyyy'
# Google Sheets credentials
SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
SERVICE_ACCOUNT_FILE = 'C:/Users/ASUS/Downloads/credentials.json'
spreadsheet_id = 'yyyyxxxxxxx'
# Authenticate with Google Sheets API
creds = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
# Function to fetch data from Google Sheets
def get_sheet_data(sheet_name):
gc = gspread.authorize(creds)
sheet = gc.open_by_key(spreadsheet_id)
worksheet = sheet.worksheet(sheet_name)
return worksheet.get_all_values()
# Command handler for starting the bot
def start(bot, update):
keyboard = [[InlineKeyboardButton("Dashboard", callback_data='dashboard')],
[InlineKeyboardButton("KPI", callback_data='kpi')]]
reply_markup = InlineKeyboardMarkup(keyboard)
update.message.reply_text('Please choose:', reply_markup=reply_markup)
# Callback handler for button presses
def button(bot, update):
query = update.callback_query
sheet_name = query.data
data = get_sheet_data(sheet_name)
message = '\n'.join(['\t'.join(row) for row in data])
query.edit_message_text(text=message)
def main():
updater = Updater(TOKEN)
dp = updater.dispatcher
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CallbackQueryHandler(button))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()
The intent is for the bot to allow users to click buttons that retrieve and display different datasets from Google Sheets. Can anyone help me resolve this initialization error?