(20250115) Can accept WhatsApp (Nimbus) integrations now.
This commit is contained in:
+56
-17
@@ -60,7 +60,8 @@ from utils_v2.api.async_quart import (
|
||||
)
|
||||
|
||||
# Data Models:
|
||||
from models.data.api.chat.auth import ChatAuthRequestHeaders, ChatAuthRequestData
|
||||
from models.api.chat.auth import ChatAuthRequestHeaders, ChatAuthRequestData
|
||||
from models.core.auth_token import CoreAuthTokenModel
|
||||
|
||||
# Common:
|
||||
from shared import constants
|
||||
@@ -198,10 +199,18 @@ async def callback_test(
|
||||
**kwargs
|
||||
):
|
||||
|
||||
# ┏┓
|
||||
# ┃┃┏┓┏┓┏┓┏┓┏┓┏┏┓┏┏
|
||||
# ┣┛┛ ┗ ┣┛┛ ┗┛┗┗ ┛┛
|
||||
# ┛
|
||||
"""
|
||||
Use this when a user wants to register a third-party chat client with your service.
|
||||
:param inbound_headers: auto-extracted by the decorators.
|
||||
:param inbound_data: auto-extracted by the decorators.
|
||||
:param inbound_files: auto-extracted by the decorators.
|
||||
:param kwargs: Any number of extra inputs supplied by the decorators.
|
||||
:return: A standard response structure.
|
||||
"""
|
||||
|
||||
# ┏┓ ┓ ┏┓┓ ┓
|
||||
# ┣┫┓┏╋┣┓ ┃ ┣┓┏┓┏┃┏
|
||||
# ┛┗┗┻┗┛┗ ┗┛┛┗┗ ┗┛┗
|
||||
|
||||
# If the session token is invalid/expired:
|
||||
if kwargs.get("session_info") is None:
|
||||
@@ -210,22 +219,52 @@ async def callback_test(
|
||||
http_code = HttpCodes.UNAUTHORIZED
|
||||
)
|
||||
|
||||
# ┏┓ ┏┳┓ ┓
|
||||
# ┣ ┏┓┏┓ ┃ ┏┓┃┏┓┏┓┏┓┏┓┏┳┓
|
||||
# ┻ ┗┛┛ ┻ ┗ ┗┗ ┗┫┛ ┗┻┛┗┗
|
||||
# ┛
|
||||
# Start by assuming failure:
|
||||
success = False
|
||||
|
||||
if inbound_data.chatClient == "telegram":
|
||||
# ┏┓ ┓ ┏┓ ┏┓ ┳┓• ┓
|
||||
# ┣ ┏┓┏┓ ┃┃┃┣┓┏┓╋┏┣┫┏┓┏┓━━┃┃┓┏┳┓┣┓┓┏┏
|
||||
# ┻ ┗┛┛ ┗┻┛┛┗┗┻┗┛┛┗┣┛┣┛ ┛┗┗┛┗┗┗┛┗┻┛
|
||||
# ┛ ┛
|
||||
|
||||
# client_response = await get_telegram_bot_info(bot_token = inbound_data.auth.botToken)
|
||||
# print("TG BOT:", json.to_string(client_response))
|
||||
client_response = await set_telegram_webhook(
|
||||
bot_token = inbound_data.auth.botToken,
|
||||
webhook_url = f"https://api.thecaoffice.com/converse/chat/webhook/{inbound_data.auth.botToken}"
|
||||
if inbound_data.chatClient == "whatsappNimbus":
|
||||
success = await current_app.whatsapp_nimbus_controller.set_token_direct(
|
||||
sql_conn = current_app.sql_writer,
|
||||
mongo_data_conn = current_app.data_mongo,
|
||||
auth_token = CoreAuthTokenModel(
|
||||
serviceType = "chat",
|
||||
client = inbound_data.chatClient,
|
||||
authType = "auth",
|
||||
auth = inbound_data.auth.model_dump(),
|
||||
user = kwargs.get("session_info"),
|
||||
clientUserId = {
|
||||
"senderId": inbound_data.auth.senderId
|
||||
},
|
||||
status = "active",
|
||||
syncFreq = 60
|
||||
),
|
||||
token_notes = {
|
||||
"apiKey": inbound_data.auth.apiKey,
|
||||
"senderId": inbound_data.auth.senderId
|
||||
},
|
||||
display_name = inbound_data.auth.senderId,
|
||||
session_token = inbound_headers["X-Session-Token"]
|
||||
)
|
||||
print("WEBHOOK JSON:", json.to_string(client_response))
|
||||
|
||||
return "ok"
|
||||
# ┳┓
|
||||
# ┣┫┏┓┏┏┓┏┓┏┓┏┏┓
|
||||
# ┛┗┗ ┛┣┛┗┛┛┗┛┗
|
||||
# ┛
|
||||
|
||||
# Done here:
|
||||
return ResponseModel(
|
||||
status_code = StatusCodes.OK if success else StatusCodes.FAILED,
|
||||
http_code = HttpCodes.SUCCESS if success else HttpCodes.INTERNAL_SERVER_ERROR,
|
||||
data = {
|
||||
"client": inbound_data.chatClient,
|
||||
"authorized": success
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user