@extends('root') @section('title', 'Test Send Template') @push('styles') @endpush @section('content')
@include('components.breadcrumb', [ 'title' => 'Test Send Template', 'links' => [ ['url' => route('client.dashboard'), 'label' => 'Dashboard Client'], ['url' => route('client.templates.index'), 'label' => 'Templates'], ], 'current' => 'Test Send' ])

Test Kirim Template

Isi nomor WhatsApp tujuan dan parameter sesuai struktur template. Form dihasilkan otomatis dari template Meta.

{{ $template->effectiveTemplateName() }}
{{-- Left: Form --}}
@csrf {{-- Phone Number --}}
Format: 628xxx tanpa tanda + atau spasi
{{-- Contact Name --}}
Jika diisi, kontak akan otomatis dibuat/diupdate.
{{-- Header Parameters --}} @if(count($headerPlaceholders) > 0)
Header Parameters
@foreach($headerPlaceholders as $idx => $placeholder)
@endforeach
@elseif($headerInfo['type'] === 'media')
Header Media *

Template ini membutuhkan header {{ $headerInfo['format'] ?? 'IMAGE' }}. Isi URL atau unggah file.

Format: JPG, PNG, MP4, PDF. Max 16MB.
URL publik untuk {{ $headerInfo['format'] ?? 'IMAGE' }}
@endif {{-- Body Parameters --}} @if(count($placeholders) > 0)
Body Parameters ({{ count($placeholders) }})
@foreach($placeholders as $idx => $placeholder)
{{ $placeholder }}
@endforeach
@endif {{-- Button Parameters (URL dynamic vars, Copy Code, Quick Reply with placeholders) --}} @if(count($buttonInfo) > 0) @php $hasUrlVars = collect($buttonInfo)->filter(fn($b) => count($b['url_vars']) > 0)->count() > 0; @endphp @if($hasUrlVars)
Button Parameters

Isi nilai untuk: Visit website (URL), Copy offer code, atau Quick reply yang punya variabel.

@foreach($buttonInfo as $button) @if(count($button['url_vars']) > 0)
@foreach($button['url_vars'] as $varIdx => $var) @endforeach
@endif @endforeach
@endif @endif {{-- No Parameters Notice --}} @if(count($placeholders) === 0 && count($headerPlaceholders) === 0 && $headerInfo['type'] !== 'media' && !(collect($buttonInfo)->filter(fn($b) => count($b['url_vars']) > 0)->count() > 0))
Template tanpa parameter

Template ini tidak memiliki variabel. Cukup isi nomor tujuan untuk mengirim.

@endif {{-- Auto Fill & Submit --}}
Kembali @if(count($placeholders) > 0 || count($headerPlaceholders) > 0) @endif
{{-- Template Info Card --}}
Info Template
Nama
{{ $template->effectiveTemplateName() }}
Kategori
{{ ucfirst($template->effectiveType()) }}
Bahasa
{{ $template->language }}
{{-- API Script Example Card --}}
Contoh Script API
{{-- PHP cURL Tab --}}
<?php
/**
 * Contoh Script Kirim Template WhatsApp
 * Template: {{ $template->effectiveTemplateName() }}
 * API Endpoint: POST /api/v1/send-template
 */

$apiKey = 'YOUR_API_KEY'; // Dapatkan dari menu Developer > API Keys
$endpoint = '{{ url('/api/v1/send-template') }}';

$payload = [
    'phone_number' => '628123456789', // Nomor tujuan (Format: 628xxx)
    'to_name' => 'John Doe', // Optional: Menyimpan nama kontak
    'name_template' => '{{ $template->effectiveTemplateName() }}',
    'language_code' => '{{ $template->language }}',
@if(count($placeholders) > 0)
    
    // Body Parameters (Urutan harus sesuai {{1}}, {{2}}, dst)
    'body_params' => [
@foreach($placeholders as $idx => $placeholder)
        '{{ $placeholder }}', // Parameter {{ $loop->iteration }}
@endforeach
    ],
@endif
@if(count($headerPlaceholders) > 0)

    // Header Parameters (Text)
    'header_params' => [
@foreach($headerPlaceholders as $idx => $placeholder)
        '{{ $placeholder }}', // Parameter {{ $loop->iteration }}
@endforeach
    ],
@elseif($headerInfo['type'] === 'media')

    // Header Media URL ({{ ucfirst($headerInfo['format'] ?? 'IMAGE') }})
    'header_media_url' => 'https://example.com/file.{{ strtolower($headerInfo['format'] === 'IMAGE' ? 'jpg' : 'mp4') }}',
@endif
@if(collect($buttonInfo)->filter(fn($b) => count($b['url_vars']) > 0)->count() > 0)

    // Button URL Parameters (Dynamic URL)
    'button_params' => [
@foreach($buttonInfo as $button)
@if(count($button['url_vars']) > 0)
        '{{ $button['index'] }}' => ['param_value'], // Index {{ $button['index'] }}: {{ $button['text'] }}
@endif
@endforeach
    ],
@endif
];

$ch = curl_init();
curl_setopt_array($ch, [
    CURLOPT_URL => $endpoint,
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS => json_encode($payload),
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'Accept: application/json',
        'X-API-KEY: Bearer ' . $apiKey,
    ],
]);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

$result = json_decode($response, true);

if ($httpCode === 200 && ($result['status'] ?? '') === 'success') {
    echo "Success! Message ID: " . $result['message_id'];
} else {
    echo "Failed: " . ($result['message'] ?? 'Unknown error');
}
{{-- JavaScript Tab --}}
const API_KEY = 'YOUR_API_KEY';
const ENDPOINT = '{{ url('/api/v1/send-template') }}';

const payload = {
    phone_number: '628123456789',
    to_name: 'John Doe',
    name_template: '{{ $template->effectiveTemplateName() }}',
    language_code: '{{ $template->language }}',
@if(count($placeholders) > 0)
    body_params: [
@foreach($placeholders as $idx => $placeholder)
        '{{ $placeholder }}', // Parameter {{ $loop->iteration }}
@endforeach
    ],
@endif
@if(count($headerPlaceholders) > 0)
    header_params: [
@foreach($headerPlaceholders as $idx => $placeholder)
        '{{ $placeholder }}', // Parameter {{ $loop->iteration }}
@endforeach
    ],
@elseif($headerInfo['type'] === 'media')
    header_media_url: 'https://example.com/file.{{ strtolower($headerInfo['format'] === 'IMAGE' ? 'jpg' : 'mp4') }}',
@endif
@if(collect($buttonInfo)->filter(fn($b) => count($b['url_vars']) > 0)->count() > 0)
    button_params: {
@foreach($buttonInfo as $button)
@if(count($button['url_vars']) > 0)
        "{{ $button['index'] }}": ["param_value"],
@endif
@endforeach
    }
@endif
};

fetch(ENDPOINT, {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'X-API-KEY': `Bearer ${API_KEY}`
    },
    body: JSON.stringify(payload)
})
.then(desc => desc.json())
.then(res => console.log(res))
.catch(err => console.error(err));
{{-- Python Tab --}}
import requests

API_KEY = 'YOUR_API_KEY'
ENDPOINT = '{{ url('/api/v1/send-template') }}'

payload = {
    "phone_number": "628123456789",
    "to_name": "John Doe",
    "name_template": "{{ $template->effectiveTemplateName() }}",
    "language_code": "{{ $template->language }}",
@if(count($placeholders) > 0)
    "body_params": [
@foreach($placeholders as $idx => $placeholder)
        "{{ $placeholder }}", # Parameter {{ $loop->iteration }}
@endforeach
    ],
@endif
@if(count($headerPlaceholders) > 0)
    "header_params": [
@foreach($headerPlaceholders as $idx => $placeholder)
        "{{ $placeholder }}", # Parameter {{ $loop->iteration }}
@endforeach
    ],
@elseif($headerInfo['type'] === 'media')
    "header_media_url": "https://example.com/file.{{ strtolower($headerInfo['format'] === 'IMAGE' ? 'jpg' : 'mp4') }}",
@endif
@if(collect($buttonInfo)->filter(fn($b) => count($b['url_vars']) > 0)->count() > 0)
    "button_params": {
@foreach($buttonInfo as $button)
@if(count($button['url_vars']) > 0)
        "{{ $button['index'] }}": ["param_value"],
@endif
@endforeach
    }
@endif
}

headers = {
    "Content-Type": "application/json",
    "Accept": "application/json",
    "X-API-KEY": f"Bearer {API_KEY}"
}

response = requests.post(ENDPOINT, json=payload, headers=headers)
print(response.json())
{{-- cURL Tab --}}
POST {{ url('/api/v1/send-template') }}
{
  "Content-Type": "application/json",
  "Accept": "application/json",
  "X-API-KEY": "Bearer YOUR_API_KEY"
}
{
  "phone_number": "628123456789",
  "to_name": "John Doe",
  "name_template": "{{ $template->effectiveTemplateName() }}",
  "language_code": "{{ $template->language }}"@if(count($placeholders) > 0 || count($headerPlaceholders) > 0 || $headerInfo['type'] === 'media' || (collect($buttonInfo)->filter(fn($b) => count($b['url_vars']) > 0)->count() > 0)),@endif
@if(count($placeholders) > 0)
  "body_params": [
@foreach($placeholders as $idx => $placeholder)
    "{{ $placeholder }}"@if(!$loop->last), @endif
@endforeach
  ]@if(count($headerPlaceholders) > 0 || $headerInfo['type'] === 'media' || (collect($buttonInfo)->filter(fn($b) => count($b['url_vars']) > 0)->count() > 0)),@endif
@endif
@if(count($headerPlaceholders) > 0)
  "header_params": [
@foreach($headerPlaceholders as $idx => $placeholder)
    "{{ $placeholder }}"@if(!$loop->last), @endif
@endforeach
  ]@if(count($headerPlaceholders) > 0 && (collect($buttonInfo)->filter(fn($b) => count($b['url_vars']) > 0)->count() > 0)),@endif
@elseif($headerInfo['type'] === 'media')
  "header_media_url": "https://example.com/file.{{ strtolower($headerInfo['format'] === 'IMAGE' ? 'jpg' : 'mp4') }}"@if(collect($buttonInfo)->filter(fn($b) => count($b['url_vars']) > 0)->count() > 0),@endif
@endif
@if(collect($buttonInfo)->filter(fn($b) => count($b['url_vars']) > 0)->count() > 0)
  "button_params": {
@foreach($buttonInfo as $button)
@if(count($button['url_vars']) > 0)
    "{{ $button['index'] }}": ["param_value"]@if(!$loop->last),@endif
@endif
@endforeach
  }
@endif
}
{{-- Right: Preview --}}
Preview Template
Preview diperbarui saat Anda mengisi form
@endsection @push('scripts') @endpush