本文整理汇总了Python中telegram.ext.Updater.start_polling方法的典型用法代码示例。如果您正苦于以下问题:Python Updater.start_polling方法的具体用法?Python Updater.start_polling怎么用?Python Updater.start_polling使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类telegram.ext.Updater
的用法示例。
在下文中一共展示了Updater.start_polling方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from telegram.ext import Updater [as 别名]
# 或者: from telegram.ext.Updater import start_polling [as 别名]
def run(self):
# Create the EventHandler and pass it your bot's token.
# updater = Updater(TELEGRAM_TOKEN, workers=5)
updater = Updater(TELEGRAM_TOKEN)
self.updater = updater
# Get the dispatcher to register handlers
dp = updater.dispatcher
# dp.add_handler(Handler(self.process_strelka_update))
dp.add_handler(CommandHandler('start', self.start))
dp.add_handler(CommandHandler('admin', self.process_admin_update))
dp.add_handler(CommandHandler('forget_me', self.process_admin_update))
dp.add_handler(RegexHandler(r'^[0-9 -]{10,}$', self.process_card_number))
dp.add_handler(CommandHandler('strelka', self.process_strelka_update))
# log all errors
# dp.add_error_handler(error)
# Start the Bot
updater.start_polling()
# Run the bot until the you presses Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
updater.idle()
示例2: main
# 需要导入模块: from telegram.ext import Updater [as 别名]
# 或者: from telegram.ext.Updater import start_polling [as 别名]
def main():
# Create the EventHandler and pass it your bot's token.
updater = Updater(secrets.bot_token)
# Get the dispatcher to register handlers
dp = updater.dispatcher
# on different commands - answer in Telegram
dp.addHandler(CommandHandler("start", start))
dp.addHandler(CommandHandler("help", help))
dp.addHandler(CommandHandler("random", random))
dp.addHandler(CommandHandler("suicide", suicide))
dp.addHandler(CommandHandler("developer", developer))
# inline query
dp.addHandler(InlineQueryHandler(search))
# on noncommand i.e message - echo the message on Telegram
dp.addHandler(MessageHandler([Filters.text], echo))
# log all errors
dp.addErrorHandler(error)
# Start the Bot
updater.start_polling()
# Run the bot until the you presses Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
updater.idle()
示例3: main
# 需要导入模块: from telegram.ext import Updater [as 别名]
# 或者: from telegram.ext.Updater import start_polling [as 别名]
def main():
# Create the EventHandler and pass it your bot's token.
updater = Updater(token="BOT_TOKEN")
# Get the dispatcher to register handlers
dp = updater.dispatcher
# simple start function
dp.add_handler(CommandHandler("start", start_callback))
# Add command handler to start the payment invoice
dp.add_handler(CommandHandler("shipping", start_with_shipping_callback))
dp.add_handler(CommandHandler("noshipping", start_without_shipping_callback))
# Optional handler if your product requires shipping
dp.add_handler(ShippingQueryHandler(shipping_callback))
# Pre-checkout handler to final check
dp.add_handler(PreCheckoutQueryHandler(precheckout_callback))
# Success! Notify your user!
dp.add_handler(MessageHandler(Filters.successful_payment, successful_payment_callback))
# log all errors
dp.add_error_handler(error)
# Start the Bot
updater.start_polling()
# Run the bot until you press Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
updater.idle()
示例4: main
# 需要导入模块: from telegram.ext import Updater [as 别名]
# 或者: from telegram.ext.Updater import start_polling [as 别名]
def main():
# Read secret token from file
with open('easy_python_bot_token', 'r') as easy_python_bot_token_file:
easy_python_bot_token = easy_python_bot_token_file.readline()
# Create the EventHandler and pass it your bot's token.
updater = Updater(easy_python_bot_token)
# Get the dispatcher to register handlers
dp = updater.dispatcher
# on different commands - answer in Telegram
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("help", help))
# on noncommand i.e message - echo the message on Telegram
dp.add_handler(MessageHandler([Filters.text], text_message_handler))
# log all errors
dp.add_error_handler(error)
# Start the Bot
updater.start_polling()
# Run the bot until the you presses Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
updater.idle()
示例5: main
# 需要导入模块: from telegram.ext import Updater [as 别名]
# 或者: from telegram.ext.Updater import start_polling [as 别名]
def main():
init()
updater = Updater(TOKEN)
dp = updater.dispatcher
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("help", help))
dp.add_handler(CommandHandler("ping", ping))
dp.add_handler(CommandHandler("nyang", nyang))
dp.add_handler(CommandHandler("rand", rand))
dp.add_handler(CommandHandler("sysstat", lambda x, y: stat(x, y, 'sys')))
dp.add_handler(CommandHandler("cpustat", lambda x, y: stat(x, y, 'cpu')))
dp.add_handler(CommandHandler("memstat", lambda x, y: stat(x, y, 'mem')))
dp.add_handler(CommandHandler("webstat", lambda x, y: stat(x, y, 'web')))
dp.add_handler(CommandHandler("diskstat", lambda x, y: stat(x, y, 'disk')))
dp.add_handler(CommandHandler("procstat", lambda x, y: stat(x, y, 'proc')))
dp.add_handler(CommandHandler("bakstat", lambda x, y: stat(x, y, 'bak')))
dp.add_handler(MessageHandler([Filters.command], unknown))
dp.add_handler(MessageHandler([Filters.text], echo))
dp.add_error_handler(error)
updater.start_polling()
updater.idle()
示例6: main
# 需要导入模块: from telegram.ext import Updater [as 别名]
# 或者: from telegram.ext.Updater import start_polling [as 别名]
def main():
"""Start the bot."""
# Create the EventHandler and pass it your bot's token.
updater = Updater("TOKEN")
# Get the dispatcher to register handlers
dp = updater.dispatcher
# on different commands - answer in Telegram
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("help", help))
# on noncommand i.e message - echo the message on Telegram
dp.add_handler(MessageHandler(Filters.text, echo))
# log all errors
dp.add_error_handler(error)
# Start the Bot
updater.start_polling()
# Run the bot until you press Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
updater.idle()
示例7: main
# 需要导入模块: from telegram.ext import Updater [as 别名]
# 或者: from telegram.ext.Updater import start_polling [as 别名]
def main():
# Create the EventHandler and passs it your bot's token.
updater = Updater(os.environ['LOGBOT'])
# Get the dispatcher to register handlers
dp = updater.dispatcher
# on different commands - answer in Telegram
dp.addHandler(CommandHandler("start", start))
dp.addHandler(CommandHandler("help", help))
# on noncommand i.e message - echo the message on Telegram
dp.addHandler(MessageHandler([Filters.text],reply))
# log all errors
dp.addErrorHandler(error)
# Start the Bot
updater.start_polling()
print 'Bot Started!!\n'
# Run the bot until the you presses Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
updater.idle()
示例8: main
# 需要导入模块: from telegram.ext import Updater [as 别名]
# 或者: from telegram.ext.Updater import start_polling [as 别名]
def main():
# Create the Updater and pass it your bot's token.
updater = Updater("181752127:AAFX10TTymBCbB4_0RKG5LxtoBJKgyYUulM")
# Get the dispatcher to register handlers
dp = updater.dispatcher
# on different commands - answer in Telegram
dp.addTelegramCommandHandler("start", start)
dp.addTelegramCommandHandler("help", help)
dp.addTelegramCommandHandler("pay", pay)
dp.addTelegramCommandHandler("fee", fee)
dp.addTelegramCommandHandler("history", history)
dp.addTelegramCommandHandler("confirm", confirm)
# on noncommand i.e message - echo the message on Telegram
dp.addTelegramInlineHandler(inlinequery)
# log all errors
dp.addErrorHandler(error)
# Start the Bot
updater.start_polling()
# Block until the user presses Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
updater.idle()
示例9: main
# 需要导入模块: from telegram.ext import Updater [as 别名]
# 或者: from telegram.ext.Updater import start_polling [as 别名]
def main():
# Create the EventHandler and pass it your bot's token.
updater = Updater()
# Get the dispatcher to register handlers
dp = updater.dispatcher
# on different commands - answer in Telegram
dp.add_handler(CommandHandler("start", c.startGame))
dp.add_handler(CommandHandler("stop", c.stop))
dp.add_handler(CommandHandler("creategame", c.createGame))
dp.add_handler(CommandHandler("join", c.joinGame))
dp.add_handler(CommandHandler("game", c.getGame))
dp.add_handler(CommandHandler("hello", c.hello))
# on noncommand i.e message - echo the message on Telegram
dp.add_handler(MessageHandler([Filters.text], c.checkPlays))
# Start the Bot
updater.start_polling()
# Run the bot until the you presses Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
updater.idle()
示例10: main
# 需要导入模块: from telegram.ext import Updater [as 别名]
# 或者: from telegram.ext.Updater import start_polling [as 别名]
def main():
print("memers default value:")
print(memers)
load_memers()
print("loaded memers:")
print(memers)
updater = Updater(apikey)
dp = updater.dispatcher
jqueue = updater.job_queue
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("help", help))
dp.add_handler(CommandHandler("test", test))
dp.add_handler(CommandHandler("ping", ping))
dp.add_handler(CommandHandler("time", time))
dp.add_handler(CommandHandler("boat", boat))
dp.add_handler(CommandHandler("ebin", ebin))
dp.add_handler(CommandHandler("stats", stats))
dp.add_handler(CommandHandler("chatinfo", chatinfo))
dp.add_handler(CommandHandler("drop", drop))
dp.add_handler(CommandHandler("shop", shop))
updater.dispatcher.add_handler(CallbackQueryHandler(shopbutton))
dp.add_handler(MessageHandler([Filters.text], parse))
dp.add_error_handler(error)
updater.start_polling(timeout=5)
# Run the bot until the user presses Ctrl-C or the process receives SIGINT, SIGTERM or SIGABRT
updater.idle()
示例11: main
# 需要导入模块: from telegram.ext import Updater [as 别名]
# 或者: from telegram.ext.Updater import start_polling [as 别名]
def main():
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
random.seed(time.time())
config = load_configuration()
# db.init(config['db_url'])
updater = Updater(token=config['auth_token'])
dispatcher = updater.dispatcher
dispatcher.add_handler(funyreplies.comrade_handler)
dispatcher.add_handler(funyreplies.its_not_handler)
dispatcher.add_handler(misc.leave_chat_handler)
#dispatcher.add_handler(misc.status_update_handler)
#dispatcher.add_handler(misc.roulette_handler)
dispatcher.add_handler(misc.help_handler)
dispatcher.add_handler(misc.until_ny_handler)
dispatcher.add_handler(timers.set_timer_handler)
dispatcher.add_handler(timers.clear_all_timers_handler)
dispatcher.add_handler(misc.log_handler, -1)
updater.start_polling(clean=True)
示例12: main
# 需要导入模块: from telegram.ext import Updater [as 别名]
# 或者: from telegram.ext.Updater import start_polling [as 别名]
def main():
# Create the EventHandler and pass it your bot's token.
updater = Updater(token=API_TOKEN)
# Get the dispatcher to register handlers
dispatcher = updater.dispatcher
# on different commands - answer in Telegram
dispatcher.addTelegramCommandHandler('start', start_command)
dispatcher.addTelegramCommandHandler('help', help_command)
dispatcher.addTelegramCommandHandler('download', download_command)
dispatcher.addTelegramCommandHandler('status', status_command)
# on noncommand i.e message - echo the message on Telegram
dispatcher.addTelegramMessageHandler(echo_command)
# log all errors
dispatcher.addErrorHandler(error_handler)
# Start the Bot
updater.start_polling()
# Run the bot until the you presses Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
updater.idle()
示例13: main
# 需要导入模块: from telegram.ext import Updater [as 别名]
# 或者: from telegram.ext.Updater import start_polling [as 别名]
def main():
# Create the EventHandler and pass it your bot's token.
updater = Updater("198643176:AAExGlD7Msdj9i62E6x36Vlt3JU3IoaOBlQ")
# Get the dispatcher to register handlers
dp = updater.dispatcher
# Add conversation handler with the states GENDER, PHOTO, LOCATION and BIO
dtRegHandler = dreamteam.register_handler()
dtIdleHandler = dreamteam.idle_handler()
dtHandler = dreamteam.DTHandler()
dp.add_handler(dtRegHandler)
dp.add_handler(dtIdleHandler)
dp.add_handler(dtHandler)
# log all errors
dp.add_error_handler(error)
# Start the Bot
updater.start_polling()
# Run the bot until the you presses Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
updater.idle()
示例14: main
# 需要导入模块: from telegram.ext import Updater [as 别名]
# 或者: from telegram.ext.Updater import start_polling [as 别名]
def main():
# Create the EventHandler and pass it your bot's token.
updater = Updater("206673727:AAH7xvkKXCuPefYM5FqSX5qvbvqSL2Rldyc")
# Get the dispatcher to register handlers
dp = updater.dispatcher
# on different commands - answer in Telegram
dp.addHandler(CommandHandler("start", start))
dp.addHandler(CommandHandler("help", help))
# on noncommand i.e message - echo the message on Telegram
dp.addHandler(MessageHandler([Filters.text], echo))
# log all errors
dp.addErrorHandler(error)
inline_caps_handler = InlineQueryHandler(inline_caps)
dp.addHandler(inline_caps_handler)
# Start the Bot
updater.start_polling()
# Run the bot until the you presses Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
updater.idle()
示例15: main
# 需要导入模块: from telegram.ext import Updater [as 别名]
# 或者: from telegram.ext.Updater import start_polling [as 别名]
def main():
config = configparser.ConfigParser()
config.read('config.ini')
# Create the EventHandler and pass it your bot's token.
updater = Updater(config['init']['token'])
# Get the dispatcher to register handlers
dp = updater.dispatcher
# on different commands - answer in Telegram
dp.addTelegramCommandHandler("start", start)
dp.addTelegramCommandHandler("add", add)
dp.addTelegramCommandHandler("help", help)
# on noncommand i.e message - echo the message on Telegram
dp.addTelegramMessageHandler(message)
# log all errors
dp.addErrorHandler(error)
# Start the Bot
updater.start_polling()
# Run the bot until the you presses Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
updater.idle()