(20250807) - Fixed Number validation issue for whatsapp nimbus whatsapp send - for value recipientNo.
This commit is contained in:
@@ -193,7 +193,8 @@ class WhatsAppNimbusController(ChatController):
|
|||||||
pdf_url = message.pdfUrl,
|
pdf_url = message.pdfUrl,
|
||||||
image_0_url = message.image0Url,
|
image_0_url = message.image0Url,
|
||||||
image_1_url = message.image1Url,
|
image_1_url = message.image1Url,
|
||||||
schedule_on = message.scheduleTs
|
schedule_on = message.scheduleTs,
|
||||||
|
country_code = message.countryCode
|
||||||
)
|
)
|
||||||
|
|
||||||
# Convert the format of the SMS client's response to the core message model.
|
# Convert the format of the SMS client's response to the core message model.
|
||||||
|
|||||||
@@ -136,6 +136,12 @@ class NimbusWhatsAppMessage(BaseModel):
|
|||||||
default=None
|
default=None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
countryCode: str | None = Field(
|
||||||
|
description="Country Code.",
|
||||||
|
frozen=True,
|
||||||
|
default="91"
|
||||||
|
)
|
||||||
|
|
||||||
# ┏┓ ┏•
|
# ┏┓ ┏•
|
||||||
# ┃ ┏┓┏┓╋┓┏┓
|
# ┃ ┏┓┏┓╋┓┏┓
|
||||||
# ┗┛┗┛┛┗┛┗┗┫
|
# ┗┛┗┛┛┗┛┗┗┫
|
||||||
@@ -170,10 +176,21 @@ class NimbusWhatsAppMessage(BaseModel):
|
|||||||
@field_validator("recipientNo", mode = "before")
|
@field_validator("recipientNo", mode = "before")
|
||||||
def validate_contact_nos(cls, value):
|
def validate_contact_nos(cls, value):
|
||||||
value = regex.replace(text = str(value), pattern = r"[^\d]", substitute_text = "")
|
value = regex.replace(text = str(value), pattern = r"[^\d]", substitute_text = "")
|
||||||
if len(value) > 10: value = regex.replace(text = str(value), pattern = r"^(91)", substitute_text = "")
|
# if len(value) > 10: value = regex.replace(text = str(value), pattern = r"^(91)", substitute_text = "")
|
||||||
value = regex.find_first(text = str(value), pattern = r"^[\d]{10}")
|
# value = regex.find_first(text = str(value), pattern = r"^[\d]{10}")
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
# @field_validator("countryCode", mode="before")
|
||||||
|
# def validate_country_code(cls, value):
|
||||||
|
# print("value", value)
|
||||||
|
# if not isinstance(value, str):
|
||||||
|
# raise ValueError("Country code must be a string.")
|
||||||
|
#
|
||||||
|
# if any(c.numeric == value for c in countries):
|
||||||
|
# return value
|
||||||
|
#
|
||||||
|
# raise ValueError(f"Invalid country code: {value}")
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -157,7 +157,8 @@ class AsyncNimbusWhatsapp:
|
|||||||
pdf_url: str = None,
|
pdf_url: str = None,
|
||||||
image_0_url: str = None,
|
image_0_url: str = None,
|
||||||
image_1_url: str = None,
|
image_1_url: str = None,
|
||||||
schedule_on: datetime.datetime = None
|
schedule_on: datetime.datetime = None,
|
||||||
|
country_code: str = None
|
||||||
) -> NimbusWhatsappSendMessageResponse:
|
) -> NimbusWhatsappSendMessageResponse:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@@ -168,6 +169,7 @@ class AsyncNimbusWhatsapp:
|
|||||||
:param image_0_url: A URL to an image file that should be sent to the recipient.
|
:param image_0_url: A URL to an image file that should be sent to the recipient.
|
||||||
:param image_1_url: A URL to an image file that should be sent to the recipient.
|
:param image_1_url: A URL to an image file that should be sent to the recipient.
|
||||||
:param schedule_on: The date-time (UTC) to schedule the message delivery at.
|
:param schedule_on: The date-time (UTC) to schedule the message delivery at.
|
||||||
|
:param country_code: Country Code for send wa.
|
||||||
:return: A structured response.
|
:return: A structured response.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -178,7 +180,8 @@ class AsyncNimbusWhatsapp:
|
|||||||
pdfUrl = pdf_url,
|
pdfUrl = pdf_url,
|
||||||
image0Url = image_0_url,
|
image0Url = image_0_url,
|
||||||
image1Url = image_1_url,
|
image1Url = image_1_url,
|
||||||
scheduleTs = schedule_on
|
scheduleTs = schedule_on,
|
||||||
|
countryCode = country_code
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -221,12 +224,13 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# sender = AsyncNimbusWhatsapp(api_key = "2c6175138e964ee8a6adc2af8faab727") # ... TCAOFF 1
|
# sender = AsyncNimbusWhatsapp(api_key = "2c6175138e964ee8a6adc2af8faab727") # ... TCAOFF 1
|
||||||
# sender = AsyncNimbusWhatsapp(api_key = "28ee15ef6df14105a855e8840540a791") # ... TCAOFF 2
|
# sender = AsyncNimbusWhatsapp(api_key = "28ee15ef6df14105a855e8840540a791") # ... TCAOFF 2
|
||||||
sender = AsyncNimbusWhatsapp(api_key = "af82dd816b6c42958d052548f40ba5f9") # ... Mr. Gaurav Gupta
|
# sender = AsyncNimbusWhatsapp(api_key = "af82dd816b6c42958d052548f40ba5f9") # ... Mr. Gaurav Gupta
|
||||||
# sender = AsyncNimbusWhatsapp(api_key = "2b6aa961ad734611b932a8bd54747403") # ... Mr. Sumeet Shirke
|
sender = AsyncNimbusWhatsapp(api_key = "cde7141633864434bdcf45778076cd78") # ... Mr. Sumeet Shirke
|
||||||
|
|
||||||
api_result = await sender.send_whatsapp(
|
api_result = await sender.send_whatsapp(
|
||||||
recipient_number = "7972314099",
|
recipient_number = "+919307317825",
|
||||||
message = f"Hello, Yatmesh ({datetime.datetime.now()})",
|
message = f"Hello, Kalyani ({datetime.datetime.now()})",
|
||||||
|
country_code="91"
|
||||||
# image_0_url = r"https://cdn.britannica.com/39/226539-050-D21D7721/Portrait-of-a-cat-with-whiskers-visible.jpg"
|
# image_0_url = r"https://cdn.britannica.com/39/226539-050-D21D7721/Portrait-of-a-cat-with-whiskers-visible.jpg"
|
||||||
)
|
)
|
||||||
print("WHATSAPP API RESULT:", api_result)
|
print("WHATSAPP API RESULT:", api_result)
|
||||||
|
|||||||
@@ -177,6 +177,12 @@ class NimbusWhatsappSendMessageResponse(BaseModel):
|
|||||||
default = None
|
default = None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
countryCode : str | None = Field(
|
||||||
|
description="",
|
||||||
|
frozen=True,
|
||||||
|
default="91"
|
||||||
|
)
|
||||||
|
|
||||||
# ┏┓ ┏•
|
# ┏┓ ┏•
|
||||||
# ┃ ┏┓┏┓╋┓┏┓
|
# ┃ ┏┓┏┓╋┓┏┓
|
||||||
# ┗┛┗┛┛┗┛┗┗┫
|
# ┗┛┗┛┛┗┛┗┗┫
|
||||||
@@ -198,6 +204,16 @@ class NimbusWhatsappSendMessageResponse(BaseModel):
|
|||||||
if isinstance(value, str): value = [value]
|
if isinstance(value, str): value = [value]
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
# @field_validator("countryCode", mode="before")
|
||||||
|
# def validate_country_code(cls, value):
|
||||||
|
# if not isinstance(value, str):
|
||||||
|
# raise ValueError("Country code must be a string.")
|
||||||
|
#
|
||||||
|
# if any(c.alpha2 == value for c in countries):
|
||||||
|
# return value
|
||||||
|
#
|
||||||
|
# raise ValueError(f"Invalid country code: {value}")
|
||||||
|
|
||||||
# ┏┓ ┏┓
|
# ┏┓ ┏┓
|
||||||
# ┃ ┓┏┏╋┏┓┏┳┓ ┣ ┓┏┏┓┏┏
|
# ┃ ┓┏┏╋┏┓┏┳┓ ┣ ┓┏┏┓┏┏
|
||||||
# ┗┛┗┻┛┗┗┛┛┗┗ ┻ ┗┻┛┗┗┛
|
# ┗┛┗┻┛┗┗┛┛┗┗ ┻ ┗┻┛┗┗┛
|
||||||
@@ -222,6 +238,9 @@ class NimbusWhatsappSendMessageResponse(BaseModel):
|
|||||||
timezone = date_time.TIMEZONE_IST
|
timezone = date_time.TIMEZONE_IST
|
||||||
).strftime("%Y%m%d%H%M")
|
).strftime("%Y%m%d%H%M")
|
||||||
|
|
||||||
|
# For country code:
|
||||||
|
if self.countryCode: api_input["country"] = self.countryCode
|
||||||
|
|
||||||
# Done here:
|
# Done here:
|
||||||
return api_input
|
return api_input
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user