Add command to get chat id
This commit is contained in:
parent
b190913e6e
commit
36f74681b2
1 changed files with 22 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
|||
import asyncio
|
||||
import configparser
|
||||
import os
|
||||
import sys
|
||||
|
@ -5,6 +6,7 @@ from dataclasses import dataclass
|
|||
from typing import Optional
|
||||
|
||||
import click
|
||||
import telegram
|
||||
|
||||
DEFAULT_CONFIG_DIR = click.get_app_dir("ofx_processor")
|
||||
DEFAULT_CONFIG_FILENAME = "config.ini"
|
||||
|
@ -54,6 +56,21 @@ def show_file_name():
|
|||
click.echo(config_file)
|
||||
|
||||
|
||||
@config.command("telegram", help="Display the bot's chat ID.")
|
||||
def print_telegram_chat_id():
|
||||
config = get_config("DEFAULT")
|
||||
click.pause("Please start a conversation with your bot, then press any key...")
|
||||
asyncio.run(print_chat_id(config))
|
||||
|
||||
|
||||
async def print_chat_id(config: "Config"):
|
||||
bot = telegram.Bot(config.telegram_bot_token)
|
||||
async with bot:
|
||||
update = (await bot.get_updates())[-1]
|
||||
chat_id = update.message.chat_id
|
||||
click.secho(f"Your chat ID is: {chat_id}", fg="green", bold=True)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Config:
|
||||
account: str
|
||||
|
@ -125,7 +142,10 @@ def get_config(account: str) -> Config:
|
|||
section = config[account]
|
||||
budget_id = section["budget"]
|
||||
token = section["token"]
|
||||
account = section["account"]
|
||||
if account == "DEFAULT":
|
||||
ynab_account_id = ""
|
||||
else:
|
||||
ynab_account_id = section["account"]
|
||||
bank_identifier = section.get("bank_identifier")
|
||||
bank_password = section.get("bank_password")
|
||||
mailgun_api_key = section.get("mailgun_api_key")
|
||||
|
@ -140,7 +160,7 @@ def get_config(account: str) -> Config:
|
|||
return handle_config_file_error(config_file, e)
|
||||
|
||||
return Config(
|
||||
account,
|
||||
ynab_account_id,
|
||||
budget_id,
|
||||
token,
|
||||
bank_identifier,
|
||||
|
|
Loading…
Reference in a new issue