Advertisement
Cesar_Leiton

Untitled

Sep 11th, 2020
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.43 KB | None | 0 0
  1. import logging
  2.  
  3. from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
  4.  
  5. person = str({ "name": "John", "age": 31, "city": "New York" }) #variable global a introducir
  6.  
  7. # Enable logging
  8. logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
  9.                     level=logging.INFO)
  10.  
  11. logger = logging.getLogger(__name__)
  12.  
  13. # Define a few command handlers. These usually take the two arguments update and
  14. # context. Error handlers also receive the raised TelegramError object in error.
  15. def start(update, context):
  16.     """Send a message when the command /start is issued."""
  17.     update.message.reply_text('We are informing you with this bot about the current mall availavility')
  18.  
  19.  
  20. def help_command(update, context):
  21.     """Send a message when the command /help is issued."""
  22.     update.message.reply_text('Help!')
  23.  
  24.  
  25. def echo(update, context):
  26.     """Echo the user message."""
  27.     update.message.reply_text('The mail availability is '+ person)
  28.     # update.message.reply_text(update.message.text)
  29.  
  30. def pic(bot, update):
  31.     chat_id = update.message.chat_id        # get the recipient´s ID
  32.     bot.send_photo(chat_id=chat_id, photo=open('./people1.png', 'rb'))
  33.     #context.bot.sendPhoto(chat_id=chat_id, photo=open('./people1.jpg', 'rb'))
  34.     #update.message.reply_text(text="I'm sorry Dave I'm afraid I can't do that.")
  35.  
  36. def main():
  37.     """Start the bot."""
  38.     # Create the Updater and pass it your bot's token.
  39.     # Make sure to set use_context=True to use the new context based callbacks
  40.     # Post version 12 this will no longer be necessary
  41.     updater = Updater("1054564599:AAF6kqAC_8haOPmcFO9SlytJB0RB9vbW8fk", use_context=True)
  42.  
  43.     # Get the dispatcher to register handlers
  44.     dp = updater.dispatcher
  45.  
  46.     # on different commands - answer in Telegram
  47.     dp.add_handler(CommandHandler("start", start))
  48.     dp.add_handler(CommandHandler("help", help_command))
  49.  
  50.     # on noncommand i.e message - echo the message on Telegram
  51.     dp.add_handler(MessageHandler(Filters.text & ~Filters.command, echo))
  52.  
  53.     dp.add_handler(CommandHandler('pic', pic))
  54.  
  55.  
  56.     # Start the Bot
  57.     updater.start_polling()
  58.  
  59.     # Run the bot until you press Ctrl-C or the process receives SIGINT,
  60.     # SIGTERM or SIGABRT. This should be used most of the time, since
  61.     # start_polling() is non-blocking and will stop the bot gracefully.
  62.     updater.idle()
  63.  
  64.  
  65. if __name__ == '__main__':
  66.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement