Resetting utils subtree.
This commit is contained in:
@@ -279,6 +279,76 @@ class WhatsAppNimbusController(ChatController):
|
||||
# Done here:
|
||||
return cumulative_results
|
||||
|
||||
# ---- ADDED BY OMKAR ----------------------------------------------------------------------------------------------
|
||||
# 2025-05-13
|
||||
|
||||
async def send_group_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.
|
||||
"""
|
||||
|
||||
# Send the SMS:
|
||||
client_response = await client.send_whatsapp_group(
|
||||
wa_group_id = message.waGroupId,
|
||||
wa_group_name = message.waGroupName,
|
||||
message = message.message,
|
||||
pdf_url = message.pdfUrl,
|
||||
image_0_url = message.image0Url,
|
||||
image_1_url = message.image1Url,
|
||||
schedule_on = message.scheduleTs
|
||||
)
|
||||
|
||||
# Convert the format of the SMS client's response to the core message model.
|
||||
sent_message_model = CoreMessageModel(
|
||||
ts = client_response.ts,
|
||||
syncTs = date_time.get_current_utc_date_time(as_string = False),
|
||||
tokenId = auth_token.authTokenId,
|
||||
serviceType = auth_token.serviceType,
|
||||
client = auth_token.client,
|
||||
clientMessageId = client_response.requestId,
|
||||
clientThreadId = message.waGroupId,
|
||||
isSent = True,
|
||||
isBroadcast = False,
|
||||
sentSuccessfully = client_response.success,
|
||||
sender = auth_token.clientUserId["senderId"],
|
||||
chat = message.waGroupId,
|
||||
message = client_response.model_dump(),
|
||||
snippet = message.message,
|
||||
aiSnippet = None,
|
||||
tags = list(set(tags + ["Chat", "Nimbus", "WhatsApp"]))
|
||||
)
|
||||
|
||||
# Save the result to the database:
|
||||
message_id = await self.save_one_message(
|
||||
mongo_data_conn = mongo_data_conn,
|
||||
message = sent_message_model
|
||||
)
|
||||
self._printer(message_id, client_response.success)
|
||||
|
||||
# Done here:
|
||||
success = True if client_response.success and message_id else False
|
||||
return ChatSendOneResult(
|
||||
success = success,
|
||||
message = "Message sent successfully." if client_response.success else "Message sending failed.",
|
||||
chatMessage = sent_message_model
|
||||
)
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
|
||||
Reference in New Issue
Block a user