(20250121) With APIs to send, list, and update tags on WhatsApp messages (through Nimbus).
This commit is contained in:
@@ -36,19 +36,24 @@ sys.path.append(".")
|
||||
sys.path.append("..")
|
||||
|
||||
# My async utils:
|
||||
from utils_v2.date_time import date_time
|
||||
from utils_v2.database.async_mysql_v2 import AsyncMySQL
|
||||
from utils_v2.database.async_mongo_v2 import AsyncMongo
|
||||
from utils_v2.cache.async_redis_cache_v2 import AsyncRedisCache
|
||||
|
||||
# Controllers:
|
||||
from controllers_v2.core.message import CoreMessageController
|
||||
from controllers_v2.message.chat.base import ChatController
|
||||
|
||||
# Models:
|
||||
from models.core.auth_token import CoreAuthTokenModel
|
||||
from models.core.message import CoreMessageModel
|
||||
from models.message.chat.send import (
|
||||
NimbusWhatsAppMessage,
|
||||
ChatSendOneResult,
|
||||
ChatSendManyResults
|
||||
)
|
||||
|
||||
# SMS Clients:
|
||||
from utils_v2.sms.india.nimbus.controllers.async_nimbus import AsyncNimbusSMS
|
||||
# Chat clients:
|
||||
from utils_v2.whatsapp.nimbus.controllers.async_nimbus_whatsapp import AsyncNimbusWhatsapp
|
||||
|
||||
# To work with datatypes:
|
||||
from typing import List, Any
|
||||
@@ -56,8 +61,11 @@ from typing import List, Any
|
||||
# To make HTTP requests:
|
||||
import httpx
|
||||
|
||||
# For asynchronous activities:
|
||||
import asyncio
|
||||
# to work with MongoDB:
|
||||
from bson.objectid import ObjectId
|
||||
|
||||
# To make abstract classes:
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
@@ -128,12 +136,65 @@ class AllChatController(ChatController):
|
||||
cache = cache,
|
||||
alert_url = alert_url,
|
||||
http_client = http_client,
|
||||
base_filter = {"client": "whatsappNimbus"},
|
||||
base_filter = {},
|
||||
debug = debug,
|
||||
debug_prefix = debug_prefix,
|
||||
debug_only_errors = debug_only_errors
|
||||
)
|
||||
|
||||
# ┏┓ ┓ ┳┳┓
|
||||
# ┗┓┏┓┏┓┏┫ ┃┃┃┏┓┏┏┏┓┏┓┏┓┏
|
||||
# ┗┛┗ ┛┗┗┻ ┛ ┗┗ ┛┛┗┻┗┫┗ ┛
|
||||
# ┛
|
||||
|
||||
async def send_one_message(
|
||||
self,
|
||||
sql_conn: AsyncMySQL,
|
||||
mongo_data_conn: AsyncMongo,
|
||||
auth_token: CoreAuthTokenModel,
|
||||
client: AsyncNimbusWhatsapp,
|
||||
message: NimbusWhatsAppMessage,
|
||||
tags: List[Any]
|
||||
) -> ChatSendOneResult:
|
||||
|
||||
"""
|
||||
To send one message from the third-party client.
|
||||
:param sql_conn: The connection to the database to use for this operation.
|
||||
:param mongo_data_conn: The connection to the database to use for this operation.
|
||||
:param auth_token: The auth-token model for the account from which the message has to be sent.
|
||||
:param client: The connection/instance of the third-party client to use to perform this operation.
|
||||
:param message: The message that you want to send to the recipient.
|
||||
:param tags: Any tags that you would like to attach to the message. To be used later for internal filtering.
|
||||
:return: The structured response model to describe the operation.
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
async def send_many_messages(
|
||||
self,
|
||||
sql_conn: AsyncMySQL,
|
||||
mongo_data_conn: AsyncMongo,
|
||||
http_client: httpx.AsyncClient,
|
||||
auth_token: CoreAuthTokenModel,
|
||||
client: AsyncNimbusWhatsapp | None,
|
||||
messages: List[NimbusWhatsAppMessage],
|
||||
tags: List[Any]
|
||||
) -> ChatSendManyResults:
|
||||
|
||||
"""
|
||||
To send many chat messages in one go.
|
||||
:param sql_conn: The connection to the database to use for this operation.
|
||||
:param mongo_data_conn: The connection to the database to use for this operation.
|
||||
:param http_client: An HTTP client to use to make API calls through the third-party client's class.
|
||||
:param auth_token: The auth-token model for the account from which the message has to be sent.
|
||||
:param client: The connection/instance of the third-party client to use to perform this operation.
|
||||
:param messages: The messages that you want to send to the recipients.
|
||||
:param tags: Any tags that you would like to attach to the message. To be used later for internal filtering.
|
||||
:return: The structured response model to describe the operation.
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
|
||||
Reference in New Issue
Block a user