orderwebhook doesn't work for Delegetorbot
hi, when I use orderedwebhook with delegatorbot on heroku, bot dont respond to user. but when using deprecated message_loop bot respond and work just fine. here some examples:
working example:
from flask import Flask, request
import telepot
from telepot.loop import MessageLoop
from telepot.loop import OrderedWebhook
try:
from Queue import Queue
except ImportError:
from queue import Queue
class Player(telepot.helper.ChatHandler):
def __init__(self, *args, **kwargs):
super(Player, self).__init__(*args, **kwargs)
def on_chat_message(self, msg):
print('something')
#working
def on_callback_query(self, msg):
print('something')
#working
def on__idle(self, event):
self.sender.sendMessage('session ended')
self.close()
application = Flask(__name__)
update_queue = Queue()
bot = telepot.DelegatorBot(TOKEN, [
include_callback_query_chat_id(
pave_event_space())(
per_chat_id(), create_open, Player, timeout=600),
])
webhook = OrderedWebhook(bot)
@application.route('/')
def hello_world():
return b'Hello World!'
@application.route('/webhook', methods=['GET', 'POST'])
def pass_update():
update_queue.put(request.data)
return 'OK'
if __name__ == '__main__':
try:
bot.setWebhook(URL)
except telepot.exception.TooManyRequestsError:
pass
application.run()
not working example:
from flask import Flask, request
import telepot
from telepot.loop import MessageLoop
from telepot.loop import OrderedWebhook
try:
from Queue import Queue
except ImportError:
from queue import Queue
class Player(telepot.helper.ChatHandler):
def __init__(self, *args, **kwargs):
super(Player, self).__init__(*args, **kwargs)
def on_chat_message(self, msg):
print('something')
#not working
def on_callback_query(msg):
print("something")
#not working
def on__idle(self, event):
self.sender.sendMessage('session ended')
self.close()
application = Flask(__name__)
bot = telepot.DelegatorBot(TOKEN, [
include_callback_query_chat_id(
pave_event_space())(
per_chat_id(), create_open, Player, timeout=600),
])
webhook = OrderedWebhook(bot)
@application.route('/')
def hello_world():
return b'Hello World!'
@application.route('/webhook', methods=['GET', 'POST'])
def pass_update():
webhook.feed(request.data)
return 'OK'
if __name__ == '__main__':
try:
bot.setWebhook(URL)
except telepot.exception.TooManyRequestsError:
pass
webhook.run_as_thread()
application.run()
i have same problem in my vps i used flask_counter example and not working i checked services status in vps services telegram was send me the message but telepot not respond to me!
@javad94, since your example is lacking some import statements and variable assignments, I modify it, make it a complete working sample, and tested it on my web host, and it works fine!
For your info, here's the complete listing of my test:
import sys
from flask import Flask, request
import telepot
from telepot.loop import OrderedWebhook
from telepot.delegate import (
per_chat_id, create_open, pave_event_space, include_callback_query_chat_id)
class Player(telepot.helper.ChatHandler):
def __init__(self, *args, **kwargs):
super(Player, self).__init__(*args, **kwargs)
def on_chat_message(self, msg):
print('on_chat_message() called')
def on_callback_query(msg):
print('on_callback_query() called')
TOKEN = sys.argv[1]
PORT = int(sys.argv[2])
URL = sys.argv[3]
application = Flask(__name__)
bot = telepot.DelegatorBot(TOKEN, [
include_callback_query_chat_id(
pave_event_space())(
per_chat_id(), create_open, Player, timeout=600),
])
webhook = OrderedWebhook(bot)
@application.route('/')
def hello_world():
return b'Hello World!'
@application.route('/webhook', methods=['GET', 'POST'])
def pass_update():
webhook.feed(request.data)
return 'OK'
if __name__ == '__main__':
try:
bot.setWebhook(URL)
except telepot.exception.TooManyRequestsError:
pass
webhook.run_as_thread()
application.run(port=PORT, debug=True)
Good luck :blush:
@javad94, I forgot to mention the versions of software I did my test on (which may be the reason why you and I got different behaviors):
Flask: 0.11.1 Python: 3.5.2