import logging
from flask import Flask
from telegram.ext import Updater,CommandHandler,MessageHandler,Filters,Dispatcher
from telegram import Bot
#enable logging
logging.basicConfig(format='%(asctime)s-%(name)s-%(levelname)s - %(message)s',level=logging.INFO)
logger = logging.getLogger(__name__)

TOKEN = "973000823:AAH0P-8kx-ca3iSAo5FRu2rutMKRAI-coxQ"

app = Flask(__name__)

@app.route('/')
def index():
 	return "Hello!"

@app.route(f'/{TOKEN}', methods=['GET','POST'])

def webhook():
	#create an update object from telegram
	update = Update.de_json(request.get_json(),bot)
	#process update
	dispatcher.process_update(update)
	return "ok"

def start(bot,update):
    print(update)
    author= update.message.from_user.first_name
    #msg= update.message.text
    reply = "Hi! {}".format(author)
    bot.send_message(chat_id=update.message.chat_id,text=reply)

def _help(bot,update):
	help_txt="Hey! This is a help text."
	bot.send_message(chat_id=update.message.chat_id,text=help_txt)

def echo_text(bot,update):
	reply=update.message.text
	bot.send_message(chat_id=update.message.chat_id,text=reply)

def echo_sticker(bot,update):
	#reply=update.message.txt
	bot.send_sticker(chat_id=update.message.chat_id,sticker=update.message.sticker.file_id)

def error(bot,update):
	logger.error("Update '%s' caused error '%s'",update,update.error)

def main():

    bot = Bot(TOKEN)
    bot.set_webhook("https://e...content-available-to-author-only...k.io/"+ TOKEN)

    dp = Dispatcher(bot,None)

    dp.add_handler(CommandHandler("start",start))
    dp.add_handler(CommandHandler("help",_help))
    dp.add_handler(MessageHandler(Filters.text,echo_text))
    dp.add_handler(MessageHandler(Filters.sticker,echo_sticker))
    dp.add_error_handler(error)

    updater.start_polling()
    logger.info("Started XYX polling...")
    updater.idle()

if __name__ == "__main__":
	main()
	app.run(port=8443)





