You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用pywa发送WhatsApp模板消息时触发(#100) Invalid parameter错误的排查咨询

pywa发送WhatsApp模板消息时触发(#100) Invalid parameter错误的排查咨询

Hey there, let's work through these issues one by one to get your template messages sending correctly!

第一个错误:(#100) Invalid parameter - "Parameter name is missing or empty"

First off, that error message is a bit misleading at first glance. You did pass the name parameter to the Template class, so the issue isn't there. The real problem is in how you're structuring the template's body parameters.

Looking at your code, you're passing a list of TextValue directly to the body argument of Template—but that's not the right structure. Pywa expects the body parameter to be a TemplateBody instance that wraps your list of TextValue objects. When you skip this wrapper, the WhatsApp Business Platform API can't parse your parameter data correctly, so it throws a generic "name is missing" error (it's complaining about the missing structural field that should contain your body parameters, not the template's own name).

第二个错误:TypeError when adding name to TextValue

The reason you get this error is simple: Template.TextValue in pywa doesn't accept a name parameter at all. It only takes a value argument. The confusion here probably comes from mixing up how Meta's template variables are defined in the business manager vs how pywa expects you to pass them. Pywa uses positional matching for template variables—you just need to pass TextValue instances in the exact order that the variables appear in your template (as you defined it in Meta's Business Manager).

如何确定哪个参数缺失?

When the WhatsApp API returns "Parameter name is missing or empty" in this context, it's not referring to a template variable name—it's pointing to a missing structural part of your API request. In your case, it's the missing TemplateBody wrapper that's causing the API to misinterpret your request as incomplete. To debug this kind of issue more clearly in the future, you can check if your request structure matches exactly what pywa's documentation expects for template messages (focus on the nested component structure, not just top-level parameters).

修正后的代码示例

Here's how your code should look to fix both issues:

from pywa import WhatsApp, types

wa = WhatsApp(phone_id="phone_id", token="token")
wa.send_template(
    to="my_phone_number",
    template=types.Template(
        name="template_name",
        language=types.Template.Language.ENGLISH,
        body=types.TemplateBody(
            values=[types.Template.TextValue(value="test_value")]
        ),
    ),
)

额外注意事项

  • Double-check that the number of TextValue instances you pass matches the number of variables in your template (and that they're in the correct order). For example, if your template says "Hello {{1}}, here's your link: {{2}}", you need two TextValue entries in the values list.
  • If your template includes buttons or other components, you'll need to add those as separate arguments to the Template class (like buttons for button components), following the same nested structure pattern.

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.08 11:18:14