> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lehar.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate a WhatsApp test reply

> Runs the production WhatsApp reply engine against a caller-supplied transcript for an in-dashboard test chat. Stateless and text-only: nothing is persisted, no message is sent via TrustSignal, and voice escalation is disabled. The agent must be a WhatsApp-channel agent. Scope `sessions:write`.



## OpenAPI

````yaml /api-reference/openapi.json post /agent/{agent_id}/whatsapp/test-reply
openapi: 3.1.0
info:
  title: Lehar API
  version: v0
  description: >-
    Customer-facing REST API for the Lehar voice-AI platform. Platform-admin
    endpoints are intentionally excluded from this reference. Regenerate with
    `npm run sync:openapi`.
servers:
  - url: https://api.lehar.ai/ca/api/v0
security:
  - ApiKeyAuth: []
  - BearerAuth: []
paths:
  /agent/{agent_id}/whatsapp/test-reply:
    post:
      tags:
        - Agents
      summary: Generate a WhatsApp test reply
      description: >-
        Runs the production WhatsApp reply engine against a caller-supplied
        transcript for an in-dashboard test chat. Stateless and text-only:
        nothing is persisted, no message is sent via TrustSignal, and voice
        escalation is disabled. The agent must be a WhatsApp-channel agent.
        Scope `sessions:write`.
      operationId: whatsapp_test_reply_ca_api_v0_agent__agent_id__whatsapp_test_reply_post
      parameters:
        - name: agent_id
          in: path
          required: true
          description: Identifier of the WhatsApp agent to test.
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                message:
                  type: string
                  description: >-
                    The latest inbound customer message to reply to. Required
                    and must be non-empty.
                conversation:
                  type: array
                  description: >-
                    Prior transcript replayed each turn (the endpoint is
                    stateless). Defaults to an empty list.
                  items:
                    type: object
                    properties:
                      direction:
                        type: string
                        description: >-
                          'inbound' for a customer turn, otherwise treated as an
                          agent turn.
                        example: inbound
                      text:
                        type: string
                        description: The message text for this turn.
                memory:
                  type: object
                  description: >-
                    Prior qualification memory to carry forward (e.g. previously
                    collected fields). Optional.
                variables:
                  type: object
                  description: >-
                    Prompt template variables merged into the agent's WhatsApp
                    prompt. Optional.
              required:
                - message
              example:
                message: Sure, I'm based in Pune.
                conversation:
                  - direction: outbound
                    text: Hi! Is now a good time to chat about the offer?
                  - direction: inbound
                    text: Yes, go ahead.
                  - direction: outbound
                    text: Great - which city are you based in?
                memory:
                  collected_fields: {}
                variables:
                  customer_name: Asha
      responses:
        '200':
          description: The engine's reply and updated qualification state for this turn.
          content:
            application/json:
              example:
                reply_text: >-
                  Thanks, Asha! Noted - Pune. Are you looking to buy within the
                  next 3 months?
                decision: reply
                reason: >-
                  Collected the customer's city; still need their buying
                  timeline.
                memory:
                  collected_fields:
                    city: Pune
                collected_fields:
                  city: Pune
                qualification_status: pending
        '400':
          description: >-
            The request body is missing/invalid, or the agent is not a WhatsApp
            agent. Messages include "message is required", "conversation must be
            a list of {direction, text} objects", "memory must be a JSON
            object", "variables must be a JSON object", "Request body must be a
            JSON object", "Request body must be JSON", and "Test chat is only
            available for WhatsApp agents".
          content:
            application/json:
              example:
                error:
                  code: invalid_request
                  message: message is required
        '401':
          description: Authentication is missing or invalid.
          content:
            application/json:
              example:
                error:
                  code: unauthorized
                  message: Authentication required
        '403':
          description: The caller lacks the required scope.
          content:
            application/json:
              example:
                error:
                  code: forbidden
                  message: Scope 'sessions:write' is required
        '404':
          description: No agent with this id is visible to the caller.
          content:
            application/json:
              example:
                error:
                  code: not_found
                  message: Agent 'agent_7f3a1c9e' not found
        '500':
          description: Unexpected server error.
          content:
            application/json:
              example:
                error:
                  code: internal_error
                  message: An unexpected error occurred
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-KEY
    BearerAuth:
      type: http
      scheme: bearer

````