return printHelp() # Main starts here token = str(os.environ["telegram_token"]) myChat_id = int(os.environ["telegram_chat_id"]) bot = telepot.Bot(token) # Bot is created from the telepot class app = Flask(__name__) URL = str(os.environ["telegram_url"]) webhook = OrderedWebhook(bot, {'chat': on_chat_message, 'callback_query': on_callback_query, 'inline_query': on_inline_query, 'chosen_inline_result': on_chosen_inline_result}) @app.route('/', methods=['GET', 'POST']) def pass_update(): webhook.feed(request.data) return 'OK' if __name__ == '__main__': app.run() printf("Executed the run") if __name__ != '__main__': try: bot.setWebhook(URL) # Sometimes it would raise this error, but webhook still set successfully. except telepot.exception.TooManyRequestsError: pass webhook.run_as_thread()
u(32), u(33), 2, # clear 29,30, skip 28 u(31), # clear 31,32,33 u(39), u(36), 2, u(37), 7, # clear 36,37,39 u(28), # discard u(38), # discard u(40), # return ] def handle(msg): print msg bot = telepot.Bot('abc') webhook = OrderedWebhook(bot, handle) webhook.run_as_thread(maxhold=8) for update in sequence: if type(update) is dict: webhook.feed(update) time.sleep(1) else: time.sleep(update)
def on_chosen_inline_result(msg): result_id, from_id, query_string = telepot.glance(msg, flavor='chosen_inline_result') print('Chosen Inline Result:', result_id, from_id, query_string) TOKEN = sys.argv[1] PORT = int(sys.argv[2]) URL = sys.argv[3] app = Flask(__name__) bot = telepot.Bot(TOKEN) webhook = OrderedWebhook(bot, {'chat': on_chat_message, 'callback_query': on_callback_query, 'inline_query': on_inline_query, 'chosen_inline_result': on_chosen_inline_result}) @app.route('/webhook', methods=['GET', 'POST']) def pass_update(): webhook.feed(request.data) return 'OK' if __name__ == '__main__': try: bot.setWebhook(URL) # Sometimes it would raise this error, but webhook still set successfully. except telepot.exception.TooManyRequestsError: pass webhook.run_as_thread() app.run(port=PORT, debug=True)
u(33), 2, # clear 29,30, skip 28 u(31), # clear 31,32,33 u(39), u(36), 2, u(37), 7, # clear 36,37,39 u(28), # discard u(38), # discard u(40), # return ] def handle(msg): print msg bot = telepot.Bot('abc') webhook = OrderedWebhook(bot, handle) webhook.run_as_thread(maxhold=8) for update in sequence: if type(update) is dict: webhook.feed(update) time.sleep(1) else: time.sleep(update)
@WebApp.route('/Telegram', methods=["POST"]) def Telegram_Handler(): BotHook.feed(request.data) return '200 OK' BotHook = OrderedWebhook( Global_Element.Tg_Bot, Tg_Bot_Client.Telegram_MessageHandler.Telegram_MessageReceive) #======================LINE Section========================= #LINE Entity Global_Element.Line_Bot = LineBotApi( Line_Config["line-bot"]["channel_access_token"]) Global_Element.Line_Hookhandler = WebhookHandler( Line_Config["line-bot"]["channel_secret"]) #處理LINE訊息 @WebApp.route('/LINE', methods=["POST"]) def LINE_Handler(): Body = request.get_data(as_text=True) LINE_MessageHandler.LINE_MessageReceive(Body) return '200 OK' if __name__ == '__main__': BotHook.run_as_thread() FileControl.Load_Table() WebApp.run(host="0.0.0.0", port=5001)