Pingtochat Docs

Pingtochat Docs

Did You Know?

Advanced visual search system powered by Ajax

leafleafleafDocy banner shape 01Docy banner shape 02Man illustrationFlower illustration

Message with parameter

Estimated reading: 3 minutes 64 views

Description:

Send a template message that includes dynamic text parameters.

Endpoint:

http://{{your_domain}}/api/v1.0/{{phone_number_id}}/{{key}}/messages
Replace the placeholders:

{{key}}: Your API key for authentication.How to create key

{{your_domain}}: Your API domain.

{{phone_number_id}}: The ID linked to your WhatsApp Business API number.

Example Payload:

{
  "messaging_product": "whatsapp",
  "recipient_type": "individual",
  "to": "91xxxxxxxxxx",
  "type": "template",
  "template": {
    "name": "marketing_newyear_va",
    "language": {
      "code": "en"
    },
    "components": [
      {
        "type": "body",
        "parameters": [
          {
            "type": "text",
            "text": "user_name"
          },
          {
            "type": "text",
            "text": "Features"
          }
        ]
      }
    ]
  }
}

Field Breakdown:

  1. messaging_product: Specifies the messaging product, always "whatsapp".
  2. recipient_type: "individual" for single-user messages.
  3. to: The recipient’s phone number in E.164 format (e.g., 91xxxxxxxxxx).
  4. type: "template" for sending a template message.
  5. template:
    • name: The name of the pre-approved template (marketing_newyear_va in this case).
    • language:
      • code: The language code of the template (e.g., en for English).
    • components:
      • type: Specifies the part of the template being populated. Use "body" for main content placeholders.
      • parameters: Contains dynamic data to replace placeholders in the template:
        • type: The type of data (e.g., "text").
        • text: The value that replaces the placeholder in the template.

Dynamic Parameters and Placeholders

Templates can include dynamic placeholders represented as variables like {{1}}, {{2}}, etc. Each placeholder is replaced by the corresponding value in the parameters array.

Template Example:

Template name: marketing_newyear_va
Template content:

Hi {{1}}, welcome to our platform! Check out these amazing {{2}}.

Example:

"parameters": [
  {
    "type": "text",
    "text": "user_name"  // Replaces {{1}}
  },
  {
    "type": "text",
    "text": "Features"  // Replaces {{2}}
  }
]

Resulting message:

Hi user_name, welcome to our platform! Check out these amazing Features.

Response Structure

A successful API call returns a 200 OK response with details about the sent message.

Example Response:

{
  "messaging_product": "whatsapp",
  "contacts": [
    {
      "input": "91xxxxxxxxxx",
      "wa_id": "91xxxxxxxxxx",
      "status_id": "NTg0MTI="
    }
  ],
  "messages": [
    {
      "id": "phoSwcGtbL",
      "message_status": "accepted"
    }
  ]
}

Response Details:

  • contacts:
    • input: The phone number from the to field.
    • wa_id: WhatsApp ID of the recipient.
    • status_id: Identifier for the delivery status.
  • messages:
    • id: A unique identifier for the message.
    • message_status: Status of the message, e.g., "accepted".

Notes and Best Practices

  1. Pre-approved Templates:
    • Templates must be created and approved in the WhatsApp Business Manager.
    • Ensure placeholders ({{1}}, {{2}}, etc.) align with the payload.
  2. Dynamic Content:
    • Use the parameters array to customize messages.
    • Include text, media, or buttons as required by your template.
  3. Language Codes:
  4. Testing:
    • Use a sandbox environment to test integrations.
    • Validate payloads and monitor logs for issues.

Sample codes

Leave a Comment

Share this Doc

Message with parameter

Or copy link

CONTENTS