Last active
January 31, 2020 12:58
-
-
Save amiryousefi/75010a5ee21176f529f830cfeaa58b0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import configparser | |
from telegram import InlineKeyboardButton, InlineKeyboardMarkup | |
from telegram.ext import Updater, MessageHandler, CommandHandler, CallbackQueryHandler, Filters | |
from APIHandler import APIHandler | |
class TodoistBot: | |
def __init__(self): | |
# Read Configs from file | |
config = configparser.ConfigParser() | |
config.read("config.ini") | |
# set Telegram bot token | |
bot_token = config['telegram']['bot_token'] | |
# set Todoist API token | |
api_token = config['todoist']['api_token'] | |
# set Todoist API URL | |
api_url = config['todoist']['api_url'] | |
# initiate a Telegram updater instance | |
self.updater = Updater(bot_token) | |
# initiate a Todoist API handler | |
self.api = APIHandler(api_token, api_url) | |
def projects(self, bot, update): | |
chat_id = update.message.chat_id | |
project_list = self.api.get_project_list() | |
keyboard = [] | |
for project in project_list: | |
keyboard.append( | |
[InlineKeyboardButton(project['name'], callback_data=project['id'])]) | |
reply_markup = InlineKeyboardMarkup(keyboard) | |
bot.send_message(chat_id=chat_id, text="Choose a Project to see tasks list", reply_markup=reply_markup) | |
def main(self): | |
updater = self.updater | |
dp = updater.dispatcher | |
# Add command handlers | |
dp.add_handler(CommandHandler('projects', self.projects)) | |
updater.start_polling() | |
updater.idle() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment