Simple Telegram Bot on Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Simple Telegram Bot on Python

I started to study how to make Telegram Bot on Python and found following example: #---- start of bot ---- from telegram.ext import Updater, InlineQueryHandler, CommandHandler import requests def get_url(): contents = requests.get('https://random.dog/woof.json').json() url = contents['url'] return url def bop(bot, update): url = get_url() chat_id = update.message.chat_id print('chat_id:', chat_id) print('dp.bot:', type(bot)) bot.send_photo(chat_id=chat_id, photo=url) def main(): updater = Updater('1069786018:AAHlHRNRZDv_AGrmEzrLeZV8yC_xXq0Mcbk') # print(dir(updater)) dp = updater.dispatcher dp.add_handler(CommandHandler('bop',bop)) updater.start_polling() updater.idle() if __name__ == '__main__': main() #---- end of bot ---- I've tested this code. It really works. But i don't understand how variables: "bot" and "update" were passed to function "bop". The only call of "bop" I see is: dp.add_handler(CommandHandler('bop',bop)) Help to figure out, please!

12th Dec 2019, 5:27 PM
Ilya Grigoriev
Ilya  Grigoriev - avatar
1 Answer
+ 2
Your code is beyond many, that's why nobody has yet answered.
27th Dec 2019, 7:33 PM
Gitansh Kumar
Gitansh Kumar - avatar