webhook code update

This commit is contained in:
Untone 2023-09-06 13:08:05 +03:00
parent aa6975e49a
commit 7a4672985f
4 changed files with 28 additions and 28 deletions

View File

@ -1,7 +1,7 @@
from sanic import Sanic
from sanic.response import text
from tgbot.config import WEBHOOK, FEEDBACK_CHAT_ID
from tgbot.config import FEEDBACK_CHAT_ID
from tgbot.handlers.handle_feedback import handle_feedback, handle_answer
from tgbot.handlers.handle_members_change import handle_join, handle_left
@ -20,17 +20,13 @@ app = Sanic(name="welcomecenter")
app.config.REGISTERED = False
@app.route('/', methods=["GET"])
@app.get('/')
async def register(req):
res = 'skipped'
if not app.config.REGISTERED:
r = register_webhook(WEBHOOK)
print(f'\n\t\t\tWEBHOOK REGISTERED:\n{r}')
print(register_webhook())
app.config.REGISTERED = True
print(r)
res = 'ok'
handle_startup()
return text(res)
return text('ok')
@app.post('/')
@ -43,6 +39,8 @@ async def handle(req):
# видимые сообщения
msg = update.get('message', update.get('edited_message'))
if msg:
if 'edited_message' in update:
msg['edit'] = True
if 'text' in msg:
if msg['chat']['id'] == msg['from']['id']:
print('private chat message')

View File

@ -151,7 +151,7 @@ def get_chat_administrators(chat_id):
# https://core.telegram.org/bots/api#getchatmember
def get_member(chat_id, member_id):
url = apiBase + f"getChatMember?chat_id={chat_id}&user_id={member_id}"
url = apiBase + f"getChatMember?chat_id={member_id}&user_id={member_id}"
r = requests.get(url)
return r.json()

View File

@ -1,6 +1,6 @@
import os
BOT_TOKEN = os.environ.get('BOT_TOKEN') or ''
WEBHOOK = os.environ.get('VERCEL_URL') or 'http://localhost:8000'
REDIS_URL = os.environ.get('REDIS_URL') or 'redis://localhost:6379'
FEEDBACK_CHAT_ID = os.environ.get('FEEDBACK_CHAT_ID').replace("-", "-100")

View File

@ -4,25 +4,27 @@ from tgbot.storage import Profile, storage
def update_button(chat_id, member_id, text='❤️'):
print('update reply markup')
prevmsg_id = storage.get(f'btn-{chat_id}-{member_id}')
if prevmsg_id:
premsg_id = prevmsg_id.decode('utf-8')
newcomer = Profile.get(member_id)
amount = len(newcomer['parents']) + 1
text += f' {amount}'
rm = {
"inline_keyboard": [
[
{
"text": text,
"callback_data": 'vouch' + member_id
}
button_message_id = storage.get(f'btn-{chat_id}-{member_id}')
print(f'button_message_id: {button_message_id}')
if button_message_id:
button_message_id = button_message_id.decode('utf-8')
print(f'button_message_id: {button_message_id}')
print('update reply markup')
newcomer = Profile.get(member_id)
amount = len(newcomer['parents']) + 1
text += f' {amount}'
rm = {
"inline_keyboard": [
[
{
"text": text,
"callback_data": 'vouch' + member_id
}
]
]
]
}
r = edit_replymarkup(chat_id, prevmsg_id, reply_markup=rm)
print(r)
}
r = edit_replymarkup(chat_id, button_message_id, reply_markup=rm)
print(r)
def handle_button(callback_query):