| 
 | 1 | +'''  | 
 | 2 | + BOT FOR TELEGRAM  | 
 | 3 | +'''  | 
 | 4 | + | 
 | 5 | +import random  | 
 | 6 | +from telegram import (ParseMode)  | 
 | 7 | +from telegram.ext import (Updater, CommandHandler)  | 
 | 8 | + | 
 | 9 | +import logging  | 
 | 10 | +logging.basicConfig(  | 
 | 11 | + format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)  | 
 | 12 | +logger = logging.getLogger(__name__)  | 
 | 13 | + | 
 | 14 | + | 
 | 15 | +def error_callback(update, context):  | 
 | 16 | + logger.warning('Update "%s" caused error "%s"', update, context.error)  | 
 | 17 | + | 
 | 18 | + | 
 | 19 | +def start(update, context):  | 
 | 20 | + '''   | 
 | 21 | + Start  | 
 | 22 | + '''  | 
 | 23 | + context.bot.send_message(update.message.chat_id,  | 
 | 24 | + "Welcome! to simple telegram bot", parse_mode=ParseMode.HTML)  | 
 | 25 | + | 
 | 26 | + '''   | 
 | 27 | + We can call other commands, without it being activated in the chat (/ help).  | 
 | 28 | + '''  | 
 | 29 | + coin(update, context)  | 
 | 30 | + | 
 | 31 | + | 
 | 32 | +def coin(update, context):  | 
 | 33 | + '''  | 
 | 34 | + ⚪️ / ⚫️ Currency  | 
 | 35 | + Generate an elatory number between 1 and 2.  | 
 | 36 | + '''  | 
 | 37 | + cid = update.message.chat_id  | 
 | 38 | + | 
 | 39 | + msg = "⚫️ face " if random.randint(1, 2) == 1 else "⚪️ cross"  | 
 | 40 | + '''  | 
 | 41 | + He responds directly on the channel where he has been spoken to.  | 
 | 42 | + '''  | 
 | 43 | + update.message.reply_text(msg)  | 
 | 44 | + | 
 | 45 | + | 
 | 46 | +def main():  | 
 | 47 | + TOKEN = "1914536904:AAF4ZnqNvyg1pk-1pCPzTqhDYggAyf-1CF8"  | 
 | 48 | + | 
 | 49 | + updater = Updater(TOKEN, use_context=True)  | 
 | 50 | + | 
 | 51 | + dp = updater.dispatcher  | 
 | 52 | + | 
 | 53 | + '''  | 
 | 54 | + Events that will activate our bot.  | 
 | 55 | + '''  | 
 | 56 | + dp.add_handler(CommandHandler('start',start))  | 
 | 57 | + dp.add_handler(CommandHandler('coin',coin))  | 
 | 58 | + | 
 | 59 | + dp.add_error_handler(error_callback)  | 
 | 60 | + | 
 | 61 | + '''  | 
 | 62 | + The bot starts  | 
 | 63 | + '''  | 
 | 64 | + updater.start_polling()  | 
 | 65 | + | 
 | 66 | + '''  | 
 | 67 | + or leave listening. Keep it from stopping.  | 
 | 68 | + '''  | 
 | 69 | + updater.idle()  | 
 | 70 | + | 
 | 71 | + | 
 | 72 | +if __name__ == '__main__':  | 
 | 73 | + print('[Telegram simple bot] Start...')  | 
 | 74 | + main()  | 
0 commit comments