[core] Add noweb engine

This commit is contained in:
allburov committed 2023-04-26 18:14:38 +07:00
1 parent 3ead3a0ba3
commit d680b6b43a
25 files changed
+1316 -119

No files matched your search

+19 -2
View File
@@ -25,6 +25,17 @@ def send_message(chat_id, text):
)
response.raise_for_status()
def send_seen(chat_id, message_id, participant):
response = requests.post(
"http://localhost:3000/api/sendSeen",
json={
"session": "default",
"chatId": chat_id,
"messageId": message_id,
"participant": participant,
},
)
response.raise_for_status()
@app.route("/")
def whatsapp_echo():
@@ -48,7 +59,13 @@ def whatsapp_webhook():
return "No files in the message"
# Number in format 791111111@c.us
from_ = payload["from"]
chat_id = payload["from"]
# Message ID - false_11111111111@c.us_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
message_id = payload['id']
# For groups - who sent the message
participant = payload.get('participant')
# IMPORTANT - Always send seen before sending new message
send_seen(chat_id=chat_id, message_id=message_id, participant=participant)
# Download the file and download it to the current folder
client_url = payload["mediaUrl"]
@@ -61,7 +78,7 @@ def whatsapp_webhook():
# Send a text back via WhatsApp HTTP API
text = f"We have downloaded file here: {path}"
print(text)
send_message(chat_id=from_, text=text)
send_message(chat_id=chat_id, text=text)
# Send OK back
return "OK"
+38 -3
View File
@@ -24,6 +24,31 @@ def send_message(chat_id, text):
)
response.raise_for_status()
def reply(chat_id, message_id, text):
response = requests.post(
"http://localhost:3000/api/reply",
json={
"chatId": chat_id,
"text": text,
"reply_to": message_id,
"session": "default",
},
)
response.raise_for_status()
def send_seen(chat_id, message_id, participant):
response = requests.post(
"http://localhost:3000/api/sendSeen",
json={
"session": "default",
"chatId": chat_id,
"messageId": message_id,
"participant": participant,
},
)
response.raise_for_status()
@app.route("/")
def whatsapp_echo():
@@ -45,9 +70,19 @@ def whatsapp_webhook():
payload = data["payload"]
# The text
text = payload["body"]
# Number in format 1231231231@c.us
from_ = payload["from"]
# Number in format 1231231231@c.us or @g.us for group
chat_id = payload["from"]
# Message ID - false_11111111111@c.us_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
message_id = payload['id']
# For groups - who sent the message
participant = payload.get('participant')
# IMPORTANT - Always send seen before sending new message
send_seen(chat_id=chat_id, message_id=message_id, participant=participant)
# Send a text back via WhatsApp HTTP API
send_message(chat_id=from_, text=text)
send_message(chat_id=chat_id, text=text)
# OR reply on the message
# reply(chat_id=chat_id, message_id=message_id, text=text)
# Send OK back
return "OK"