webhook update
This commit is contained in:
parent
7d98212818
commit
e02203b3dc
21
bot.py
21
bot.py
@ -5,7 +5,8 @@ import vk
|
||||
import threading
|
||||
import re
|
||||
import logging
|
||||
from credentials import token, vk_app_id
|
||||
import cherrypy
|
||||
from credentials import token, vk_app_id, local_port
|
||||
|
||||
logging.basicConfig(format='%(levelname)-8s [%(asctime)s] %(message)s', level=logging.WARNING, filename='vk.log')
|
||||
|
||||
@ -129,4 +130,20 @@ def reply(message):
|
||||
message=message.text)
|
||||
|
||||
|
||||
bot.polling(none_stop=True)
|
||||
class WebhookServer(object):
|
||||
# index равнозначно /, т.к. отсутствию части после ip-адреса (грубо говоря)
|
||||
@cherrypy.expose
|
||||
def index(self):
|
||||
length = int(cherrypy.request.headers['content-length'])
|
||||
json_string = cherrypy.request.body.read(length).decode("utf-8")
|
||||
update = telebot.types.Update.de_json(json_string)
|
||||
bot.process_new_updates([update])
|
||||
return ''
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
bot.remove_webhook()
|
||||
bot.set_webhook('https://bot.asergey.me/{}/'.format(token))
|
||||
cherrypy.config.update(
|
||||
{'server.socket_host': '127.0.0.1', 'server.socket_port': local_port, 'engine.autoreload.on': False})
|
||||
cherrypy.quickstart(WebhookServer(), '/', {'/': {}})
|
||||
|
Loading…
x
Reference in New Issue
Block a user