<reponame>hialisabet/FirstStepsPTB
from telegram.ext import Updater
from telegram.ext import CommandHandler
from telegram.ext import CallbackContext
from telegram.ext import MessageHandler
from telegram.ext.filters import Filters
from telegram import Update
from telegram import ReplyKeyboardMarkup
from telegram.chataction import ChatAction

token = "TOKEN"
messages = {
    "msg_start": "سلام {} {} \n به ربات خوش آمدید.",
    "msg_sum": "مجموع اعداد به صورت زیر است: \n {}",
    "msg_main_handler": "منو اصلی:",
    "msg_select_language": "زبان موردنظر خو را انتخاب کنید:",
    "msg_contact": "ارتباط با ما: \n کانال تلگرامی: \n وبسایت",
    "btn_courses": "دوره ها",
    "btn_articles": "مقالات",
    "btn_help": "راهنمایی",
    "btn_contact_us": "تماس با ما",
    "btn_python": "پایتون",
    "btn_kotlin": "کاتلین",
    "btn_return": "بازگشت"
}


def start_handler(update: Update, context: CallbackContext):
    chat_id = update.message.chat_id
    first_name = update.message.chat.first_name
    last_name = update.message.chat.last_name
    context.bot.send_chat_action(chat_id, ChatAction.TYPING)
    update.message.reply_text(text=messages["msg_start"].format(first_name, last_name))
    main_menu_handler(update, context)


def main_menu_handler(update: Update, context: CallbackContext):
    buttons = [
        [messages["btn_articles"], messages["btn_courses"]],
        [messages["btn_contact_us"]],
        [messages["btn_help"]]
    ]
    update.message.reply_text(
        text=messages["msg_main_handler"],
        reply_markup=ReplyKeyboardMarkup(buttons, resize_keyboard=True)
    )


def send_music_handler(update: Update, context: CallbackContext):
    chat_id = update.message.chat_id
    with open("./Music.mp3", "rb") as music:
        context.bot.send_chat_action(chat_id, ChatAction.UPLOAD_AUDIO)
        context.bot.sendAudio(chat_id,
                              music,
                              caption="آهنگ",
                              duration=600,
                              disable_notification=True)


def send_photo_handler(update: Update, context: CallbackContext):
    chat_id = update.message.chat_id
    with open("./Image.jpg", "rb") as img:
        context.bot.send_chat_action(chat_id, ChatAction.UPLOAD_PHOTO)
        context.bot.sendPhoto(chat_id,
                              img,
                              caption="لوگو")


def send_doc_handler(update: Update, context: CallbackContext):
    chat_id = update.message.chat_id
    with open("./Doc.pdf", "rb") as doc:
        context.bot.send_chat_action(chat_id, ChatAction.UPLOAD_DOCUMENT)
        context.bot.sendDocument(chat_id,
                                 doc,
                                 caption="فایل")


def main():
    updater = Updater(token, use_context=True)
    updater.dispatcher.add_handler(CommandHandler("start", start_handler))
    updater.dispatcher.add_handler(CommandHandler("music", send_music_handler))
    updater.dispatcher.add_handler(CommandHandler("photo", send_photo_handler))
    updater.dispatcher.add_handler(MessageHandler(Filters.regex(messages["btn_articles"]), send_doc_handler))
    updater.start_polling()
    updater.idle()


main()
