Error sending Whatsapp using Azure Communication Service : InvalidParameter: (#100) - Stack Overflow

I need some help.Messaging whatsapp using azure communication services was working fine until a few da

I need some help. Messaging whatsapp using azure communication services was working fine until a few days ago. I'm started receiving this message:

An unexpected error occurred: (BadRequest) Given request contains a parameter for WhatsApp which was invalid. This includes channel ID and template parameters.
Code: BadRequest
Message: Given request contains a parameter for WhatsApp which was invalid. This includes channel ID and template parameters.
Inner error: {
    "code": "WhatsAppAdminClient+WaErrorCode.InvalidParameter",
    "message": "InvalidParameter: (#100) Invalid parameter. Invalid parameter."
}

The odd thing is that sometimes the message I sent, despite the error message.

I've been searching everywhere what InvalidParameter: (#100) means. I yet to find a solution.

Does someone know?

Here is the python code that run my messaging:

from azuremunication.messages import NotificationMessagesClient
messaging_client = NotificationMessagesClient.from_connection_string(connection_keys.azure_whatsapp_endpoint)

def send_whatsapp_template_message(recipient_number, topic , email, subject, phone_number,user_name):
    try:
        value1 = MessageTemplateText(name="1", text=f"'{topic}'")
        
        value2 = MessageTemplateText(name="2", text=f"'{user_name}'")
        value3 = MessageTemplateText(name="3", text=f"'{subject}'")
        value4 = MessageTemplateText(name="4", text=f"'{email}'")
        value5 = MessageTemplateText(name="5", text=f"'{phone_number}'")
        
        # Adjust the bindings to match your template
        template_bindings = WhatsAppMessageTemplateBindings(
            header=[WhatsAppMessageTemplateBindingsComponent(ref_value=value1.name)],
            
            body=[WhatsAppMessageTemplateBindingsComponent(ref_value=value2.name),
                  WhatsAppMessageTemplateBindingsComponent(ref_value=value3.name),
                  WhatsAppMessageTemplateBindingsComponent(ref_value=value4.name),
                  WhatsAppMessageTemplateBindingsComponent(ref_value=value5.name)]
        )
        
        #Retreive Template
        lang_code = search_pandas_df(dataframe_file=bot_settings.languages_whatsapp_templates,
                                    search_column = "Language",
                                    search_value = session['selected_language'],
                                    target_column =  "lang_code",
                                     )
        
        template = search_pandas_df(dataframe_file=bot_settings.languages_whatsapp_templates,
                                    search_column = "Language",
                                    search_value = session['selected_language'],
                                    target_column =  "template",
                                     )
        
        #Create templateInputs
        input_template: MessageTemplate = MessageTemplate(
            name=template,  
            language=lang_code,
            template_values=[value1, value2, value3,value4,value5],  
            bindings=template_bindings
        )
        
        template_options = TemplateNotificationContent(
            channel_registration_id=connection_keys.azure_channel_registration_id_bsai,
            to=[recipient_number],
            template=input_template
        )

message_responses = messaging_client.send(template_options) #error occurs here
response = message_responses.receipts[0]

The error occurs at messaging_client.send(template_options), which is an azure module. I inspected it and I'm passing all the variables correctly. This has been running for about 5 months without issues.

My template variables and template names are fine. As mentioned earlier, the failure is occasional, perhaps 1 out of 3 or 4 messages.

I'll appreciate any leads on the matter

I need some help. Messaging whatsapp using azure communication services was working fine until a few days ago. I'm started receiving this message:

An unexpected error occurred: (BadRequest) Given request contains a parameter for WhatsApp which was invalid. This includes channel ID and template parameters.
Code: BadRequest
Message: Given request contains a parameter for WhatsApp which was invalid. This includes channel ID and template parameters.
Inner error: {
    "code": "WhatsAppAdminClient+WaErrorCode.InvalidParameter",
    "message": "InvalidParameter: (#100) Invalid parameter. Invalid parameter."
}

The odd thing is that sometimes the message I sent, despite the error message.

I've been searching everywhere what InvalidParameter: (#100) means. I yet to find a solution.

Does someone know?

Here is the python code that run my messaging:

from azuremunication.messages import NotificationMessagesClient
messaging_client = NotificationMessagesClient.from_connection_string(connection_keys.azure_whatsapp_endpoint)

def send_whatsapp_template_message(recipient_number, topic , email, subject, phone_number,user_name):
    try:
        value1 = MessageTemplateText(name="1", text=f"'{topic}'")
        
        value2 = MessageTemplateText(name="2", text=f"'{user_name}'")
        value3 = MessageTemplateText(name="3", text=f"'{subject}'")
        value4 = MessageTemplateText(name="4", text=f"'{email}'")
        value5 = MessageTemplateText(name="5", text=f"'{phone_number}'")
        
        # Adjust the bindings to match your template
        template_bindings = WhatsAppMessageTemplateBindings(
            header=[WhatsAppMessageTemplateBindingsComponent(ref_value=value1.name)],
            
            body=[WhatsAppMessageTemplateBindingsComponent(ref_value=value2.name),
                  WhatsAppMessageTemplateBindingsComponent(ref_value=value3.name),
                  WhatsAppMessageTemplateBindingsComponent(ref_value=value4.name),
                  WhatsAppMessageTemplateBindingsComponent(ref_value=value5.name)]
        )
        
        #Retreive Template
        lang_code = search_pandas_df(dataframe_file=bot_settings.languages_whatsapp_templates,
                                    search_column = "Language",
                                    search_value = session['selected_language'],
                                    target_column =  "lang_code",
                                     )
        
        template = search_pandas_df(dataframe_file=bot_settings.languages_whatsapp_templates,
                                    search_column = "Language",
                                    search_value = session['selected_language'],
                                    target_column =  "template",
                                     )
        
        #Create templateInputs
        input_template: MessageTemplate = MessageTemplate(
            name=template,  
            language=lang_code,
            template_values=[value1, value2, value3,value4,value5],  
            bindings=template_bindings
        )
        
        template_options = TemplateNotificationContent(
            channel_registration_id=connection_keys.azure_channel_registration_id_bsai,
            to=[recipient_number],
            template=input_template
        )

message_responses = messaging_client.send(template_options) #error occurs here
response = message_responses.receipts[0]

The error occurs at messaging_client.send(template_options), which is an azure module. I inspected it and I'm passing all the variables correctly. This has been running for about 5 months without issues.

My template variables and template names are fine. As mentioned earlier, the failure is occasional, perhaps 1 out of 3 or 4 messages.

I'll appreciate any leads on the matter

Share Improve this question edited Mar 26 at 3:21 Suresh Chikkam 3,6062 gold badges4 silver badges12 bronze badges Recognized by Microsoft Azure Collective asked Mar 22 at 10:33 Kakobo kakoboKakobo kakobo 93 bronze badges 1
  • Avoid adding extra quotes around template values. Instead of text=f"'{topic}'", just use text=topic – Suresh Chikkam Commented Mar 24 at 9:26
Add a comment  | 

1 Answer 1

Reset to default 0

It might be related to a rate limit or transient error on Azure's end. You could implement retry logic with exponential backoff to handle these cases. Sometimes, even small delays or retries can resolve intermittent issues.

Code:

import time
from azure.core.exceptions import HttpResponseError

MAX_RETRIES = 5
RETRY_DELAY = 2  # Initial delay in seconds

def send_with_retry(messaging_client, template_options):
    retries = 0
    while retries < MAX_RETRIES:
        try:
            message_responses = messaging_client.send(template_options)
            return message_responses
        except HttpResponseError as e:
            print(f"Attempt {retries + 1} failed with error: {e.message}")
            if retries < MAX_RETRIES - 1:
                retries += 1
                time.sleep(RETRY_DELAY * (2 ** retries))  # Exponential backoff
            else:
                raise
  • Verify that the WhatsApp template you're trying to use is still active and has not been modified or deactivated in the Azure Communication Services portal. Sometimes templates are updated or removed, which would lead to this kind of error. Double-check the template name and structure to ensure they're still valid.

  • template_bindings which you are passing in the request are structured properly. The ref_value for each MessageTemplateText component should match the placeholders defined in the actual WhatsApp template. Even a small mismatch in the order or number of placeholders can cause the API to fail.

Log:

[INFO] 2025-03-25 10:00:00 - Starting to send WhatsApp message.
[INFO] 2025-03-25 10:00:00 - Preparing template data.
[INFO] 2025-03-25 10:00:01 - Template data prepared successfully.
[INFO] 2025-03-25 10:00:01 - Binding template values for placeholders.
[INFO] 2025-03-25 10:00:02 - Template bindings completed.
[INFO] 2025-03-25 10:00:02 - Retrieving template language code and template name.
[INFO] 2025-03-25 10:00:03 - Retrieved language code: en, Template: "order_update_template".
[INFO] 2025-03-25 10:00:03 - Creating template input for message.
[INFO] 2025-03-25 10:00:04 - Template input created successfully.
[INFO] 2025-03-25 10:00:04 - Preparing notification content.
[INFO] 2025-03-25 10:00:05 - Notification content prepared for channel registration ID: azure_channel_registration_id_bsai.
[INFO] 2025-03-25 10:00:06 - Sending message to recipient: +1234567890.
[INFO] 2025-03-25 10:00:06 - Message sent successfully. Waiting for receipt.
[INFO] 2025-03-25 10:00:07 - Receipt received: Message ID: 56789, Status: Delivered.
[INFO] 2025-03-25 10:00:07 - Message sent successfully to recipient +1234567890 with message ID: 56789.
[INFO] 2025-03-25 10:00:07 - Process completed without errors.
[INFO] 2025-03-25 10:00:07 - End of log for WhatsApp message request.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744318545a4568299.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信