webhook code update
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
from sanic import Sanic
|
from sanic import Sanic
|
||||||
from sanic.response import text
|
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_feedback import handle_feedback, handle_answer
|
||||||
from tgbot.handlers.handle_members_change import handle_join, handle_left
|
from tgbot.handlers.handle_members_change import handle_join, handle_left
|
||||||
@@ -20,17 +20,13 @@ app = Sanic(name="welcomecenter")
|
|||||||
app.config.REGISTERED = False
|
app.config.REGISTERED = False
|
||||||
|
|
||||||
|
|
||||||
@app.route('/', methods=["GET"])
|
@app.get('/')
|
||||||
async def register(req):
|
async def register(req):
|
||||||
res = 'skipped'
|
|
||||||
if not app.config.REGISTERED:
|
if not app.config.REGISTERED:
|
||||||
r = register_webhook(WEBHOOK)
|
print(register_webhook())
|
||||||
print(f'\n\t\t\tWEBHOOK REGISTERED:\n{r}')
|
|
||||||
app.config.REGISTERED = True
|
app.config.REGISTERED = True
|
||||||
print(r)
|
|
||||||
res = 'ok'
|
|
||||||
handle_startup()
|
handle_startup()
|
||||||
return text(res)
|
return text('ok')
|
||||||
|
|
||||||
|
|
||||||
@app.post('/')
|
@app.post('/')
|
||||||
@@ -43,6 +39,8 @@ async def handle(req):
|
|||||||
# видимые сообщения
|
# видимые сообщения
|
||||||
msg = update.get('message', update.get('edited_message'))
|
msg = update.get('message', update.get('edited_message'))
|
||||||
if msg:
|
if msg:
|
||||||
|
if 'edited_message' in update:
|
||||||
|
msg['edit'] = True
|
||||||
if 'text' in msg:
|
if 'text' in msg:
|
||||||
if msg['chat']['id'] == msg['from']['id']:
|
if msg['chat']['id'] == msg['from']['id']:
|
||||||
print('private chat message')
|
print('private chat message')
|
||||||
|
@@ -151,7 +151,7 @@ def get_chat_administrators(chat_id):
|
|||||||
|
|
||||||
# https://core.telegram.org/bots/api#getchatmember
|
# https://core.telegram.org/bots/api#getchatmember
|
||||||
def get_member(chat_id, member_id):
|
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)
|
r = requests.get(url)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
|
BOT_TOKEN = os.environ.get('BOT_TOKEN') or ''
|
||||||
WEBHOOK = os.environ.get('VERCEL_URL') or 'http://localhost:8000'
|
WEBHOOK = os.environ.get('VERCEL_URL') or 'http://localhost:8000'
|
||||||
REDIS_URL = os.environ.get('REDIS_URL') or 'redis://localhost:6379'
|
REDIS_URL = os.environ.get('REDIS_URL') or 'redis://localhost:6379'
|
||||||
FEEDBACK_CHAT_ID = os.environ.get('FEEDBACK_CHAT_ID').replace("-", "-100")
|
FEEDBACK_CHAT_ID = os.environ.get('FEEDBACK_CHAT_ID').replace("-", "-100")
|
@@ -4,25 +4,27 @@ from tgbot.storage import Profile, storage
|
|||||||
|
|
||||||
|
|
||||||
def update_button(chat_id, member_id, text='❤️'):
|
def update_button(chat_id, member_id, text='❤️'):
|
||||||
print('update reply markup')
|
button_message_id = storage.get(f'btn-{chat_id}-{member_id}')
|
||||||
prevmsg_id = storage.get(f'btn-{chat_id}-{member_id}')
|
print(f'button_message_id: {button_message_id}')
|
||||||
if prevmsg_id:
|
if button_message_id:
|
||||||
premsg_id = prevmsg_id.decode('utf-8')
|
button_message_id = button_message_id.decode('utf-8')
|
||||||
newcomer = Profile.get(member_id)
|
print(f'button_message_id: {button_message_id}')
|
||||||
amount = len(newcomer['parents']) + 1
|
print('update reply markup')
|
||||||
text += f' {amount}'
|
newcomer = Profile.get(member_id)
|
||||||
rm = {
|
amount = len(newcomer['parents']) + 1
|
||||||
"inline_keyboard": [
|
text += f' {amount}'
|
||||||
[
|
rm = {
|
||||||
{
|
"inline_keyboard": [
|
||||||
"text": text,
|
[
|
||||||
"callback_data": 'vouch' + member_id
|
{
|
||||||
}
|
"text": text,
|
||||||
|
"callback_data": 'vouch' + member_id
|
||||||
|
}
|
||||||
|
]
|
||||||
]
|
]
|
||||||
]
|
}
|
||||||
}
|
r = edit_replymarkup(chat_id, button_message_id, reply_markup=rm)
|
||||||
r = edit_replymarkup(chat_id, prevmsg_id, reply_markup=rm)
|
print(r)
|
||||||
print(r)
|
|
||||||
|
|
||||||
|
|
||||||
def handle_button(callback_query):
|
def handle_button(callback_query):
|
||||||
|
Reference in New Issue
Block a user