(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
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
|
||||
+19
-2
@@ -80,6 +80,9 @@ from controllers_v2.message.sms.all_sms import AllSMSController
|
||||
from controllers_v2.message.sms.nimbus_sms_india import NimbusSMSIndiaController
|
||||
from controllers_v2.message.sms.savvy_bulk_sms_kenya import SavvyBulkSMSKenyaController
|
||||
# ---
|
||||
from controllers_v2.message.chat.all_chat import AllChatController
|
||||
from controllers_v2.message.chat.whatsapp_nimbus import WhatsAppNimbusController
|
||||
# ---
|
||||
from controllers_v2.finstitutions.trading.all_trading import AllTradingController
|
||||
from controllers_v2.finstitutions.trading.zerodha_kite import ZerodhaKiteTradingController
|
||||
from controllers_v2.finstitutions.trading.icici_breeze import ICICIBreezeTradingController
|
||||
@@ -110,7 +113,7 @@ from api.blueprints.sms.list import sms_list_bp
|
||||
from api.blueprints.sms.tags import sms_update_tags_bp
|
||||
|
||||
# Chat Blueprints:
|
||||
# from api.blueprints.chat.auth import chat_auth_bp
|
||||
from api.blueprints.chat.auth import chat_auth_bp
|
||||
# from api.blueprints.chat.webhook import chat_webhook_bp
|
||||
|
||||
# Software Blueprints:
|
||||
@@ -179,7 +182,7 @@ app.register_blueprint(sms_list_bp, url_prefix = f"/{MODULE_BASE}/sms")
|
||||
app.register_blueprint(sms_update_tags_bp, url_prefix = f"/{MODULE_BASE}/sms")
|
||||
|
||||
# Chat Blueprints:
|
||||
# app.register_blueprint(chat_auth_bp, url_prefix = f"/{MODULE_BASE}/chat")
|
||||
app.register_blueprint(chat_auth_bp, url_prefix = f"/{MODULE_BASE}/chat")
|
||||
# app.register_blueprint(chat_webhook_bp, url_prefix = f"/{MODULE_BASE}/chat")
|
||||
|
||||
# Software Blueprints:
|
||||
@@ -455,6 +458,20 @@ async def app_startup(**kwargs):
|
||||
debug = enable_debugging
|
||||
)
|
||||
|
||||
# Messages / Chat Controllers:
|
||||
current_app.chat_controller = AllChatController(
|
||||
cache = current_app.module_cache,
|
||||
http_client = current_app.http_client,
|
||||
alert_url = current_app.script_data["alerts"]["url"],
|
||||
debug = enable_debugging
|
||||
)
|
||||
current_app.whatsapp_nimbus_controller = WhatsAppNimbusController(
|
||||
cache = current_app.module_cache,
|
||||
http_client = current_app.http_client,
|
||||
alert_url = current_app.script_data["alerts"]["url"],
|
||||
debug = enable_debugging
|
||||
)
|
||||
|
||||
# Finstitutions / Trading Controllers:
|
||||
current_app.trading_controller = AllTradingController(
|
||||
cache = current_app.module_cache,
|
||||
|
||||
Reference in New Issue
Block a user