text: from telegram.ext import Updater
  from telegram.ext import CommandHandler
  from telegram.ext import CallbackContext
  from telegram.ext import MessageHandler
  from telegram.ext import CallbackQueryHandler
  from telegram.ext import ConversationHandler
  from telegram.ext.filters import Filters
  from telegram import Update
  from telegram import ReplyKeyboardMarkup
  from telegram import InlineKeyboardMarkup
  from telegram import InlineKeyboardButton
  from telegram import ParseMode
  from telegram.chataction import ChatAction
  import requests
  import logging
  
  token = "TOKEN"
  # open weather map api key
  api_key = "KEY"
  logging.basicConfig(level=logging.INFO)
  FIRST, SECOND = range(2)
  
  messages = {
      "msg_start": "سلام {} {} \n به ربات خوش آمدید.",
      "msg_sum": "مجموع اعداد به صورت زیر است: \n {}",
      "msg_main_handler": "منو اصلی:",
      "msg_select_language": "زبان موردنظر خو را انتخاب کنید:",
      "msg_contact": "ارتباط با ما: \n کانال تلگرامی: \n وبسایت",
      "btn_city_selection": "انتخاب شهر",
      "btn_weather_condition": "وضعیت هوا",
      "btn_help": "راهنمایی",
      "btn_contact_us": "تماس با ما",
      "btn_python": "پایتون",
      "btn_kotlin": "کاتلین",
      "btn_return": "بازگشت"
  }
  cities = {
      "tehran": [
          [
              InlineKeyboardButton("تهران", callback_data="112931"),
              InlineKeyboardButton("2", callback_data="2")
  
          ]
      ]
  }
  conversation = {}
  
  
  def get_data(city_id):
      url = "http://api.openweathermap.org/data/2.5/weather?id=" + city_id + "&appid=" + api_key
      res = requests.get(url)
      data = res.json()
      temp = data["main"]["temp"] - 273
      return temp
  
  
  def start_handler(update: Update, context: CallbackContext):
      chat_id = update.message.chat_id
      first_name = update.message.chat.first_name
      context.bot.send_chat_action(chat_id, ChatAction.TYPING)
      update.message.reply_text(text="<i>سلام</i>", parse_mode=ParseMode.HTML)
      main_menu_handler(update, context)
      logging.info("({} - {}) start the bot.".format(first_name, chat_id))
  
  
  def main_menu_handler(update: Update, context: CallbackContext):
      buttons = [
          [messages["btn_weather_condition"], messages["btn_city_selection"]],
          [messages["btn_contact_us"]],
          [messages["btn_help"]]
      ]
      update.message.reply_text(
          text=messages["msg_main_handler"],
          reply_markup=ReplyKeyboardMarkup(buttons, resize_keyboard=True)
      )
  
  
  def province_selection_handler(update: Update, context: CallbackContext):
      buttons = [
          [
              InlineKeyboardButton("تهران", callback_data="tehran"),
              InlineKeyboardButton("2", callback_data="2"),
              InlineKeyboardButton("3", callback_data="3")
          ]
      ]
      update.message.reply_text(text="استان را انتخاب کتید:", reply_markup=InlineKeyboardMarkup(buttons))
      return FIRST
  
  
  def city_selection_handler(update: Update, context: CallbackContext):
      query = update.callback_query
      button = cities[query.data]
      context.bot.editMessageText(chat_id=query.message.chat_id,
                                  message_id=query.message.message_id,
                                  text="شهر را انتخاب کنبد:", reply_markup=InlineKeyboardMarkup(button))
      return SECOND
  
  
  def end_handler(update: Update, context: CallbackContext):
      global conversation
      query = update.callback_query
      chat_id = query.message.chat_id
      city_id = query.data
      user_name = query.message.chat.first_name
      logging.info("{} select city {}".format(user_name, city_id))
      conversation[chat_id] = str(city_id)
      context.bot.editMessageText(chat_id=chat_id, message_id=query.message.message_id, text="شهر شما انتخاب شد.")
      return ConversationHandler.END
  
  
  def send_data_handler(update: Update, context: CallbackContext):
      global conversation
      chat_id = update.message.chat_id
      city_id = conversation[chat_id]
      data = get_data(city_id)
      update.message.reply_text(text="دما: {}".format(data))
  
  
  def main():
      updater = Updater(token, use_context=True)
      updater.dispatcher.add_handler(ConversationHandler(
          entry_points=[MessageHandler(Filters.regex(messages["btn_city_selection"]), province_selection_handler)],
          states={
              FIRST: [CallbackQueryHandler(city_selection_handler)],
              SECOND: [CallbackQueryHandler(end_handler)]
          },
          fallbacks=[MessageHandler(Filters.regex(messages["btn_city_selection"]), province_selection_handler)],
          allow_reentry=True
      ))
      updater.dispatcher.add_handler(CommandHandler("start", start_handler))
      updater.dispatcher.add_handler(MessageHandler(Filters.regex(messages["btn_weather_condition"]), send_data_handler))
      updater.start_polling()
      updater.idle()
  
  
  main()
  