Initial baseline WACloud CI3 production
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Whatsapp_template extends CI_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('cronjob/WhatsappTemplate_model');
|
||||
}
|
||||
|
||||
public function index($phone_number = null)
|
||||
{
|
||||
if (!$phone_number) {
|
||||
$this->output
|
||||
->set_status_header(400)
|
||||
->set_content_type('application/json')
|
||||
->set_output(json_encode(['success' => false, 'message' => 'Parameter phone_number dibutuhkan di URL']));
|
||||
return;
|
||||
}
|
||||
|
||||
$wa_number = $this->WhatsappTemplate_model->get_whatsapp_number_by_phone($phone_number);
|
||||
|
||||
if (!$wa_number) {
|
||||
$this->output
|
||||
->set_status_header(404)
|
||||
->set_content_type('application/json')
|
||||
->set_output(json_encode(['success' => false, 'message' => 'Nomor WhatsApp tidak ditemukan']));
|
||||
return;
|
||||
}
|
||||
|
||||
$templates = $this->WhatsappTemplate_model->get_templates_from_meta($wa_number->phone_waba_id,$wa_number->access_token);
|
||||
|
||||
if (!isset($templates['data'])) {
|
||||
$this->output
|
||||
->set_status_header(500)
|
||||
->set_content_type('application/json')
|
||||
->set_output(json_encode(['success' => false, 'message' => 'Gagal mengambil data template dari Meta']));
|
||||
return;
|
||||
}
|
||||
|
||||
$saved = [];
|
||||
foreach ($templates['data'] as $template) {
|
||||
$data = [
|
||||
'template_id' => $template['id'],
|
||||
'template_name' => $template['name'],
|
||||
'language' => $template['language'],
|
||||
'category' => $template['category'],
|
||||
'status' => $template['status'],
|
||||
'components' => json_encode($template['components']),
|
||||
'last_updated' => date('Y-m-d H:i:s'),
|
||||
'whatsapp_number_id' => $wa_number->id,
|
||||
];
|
||||
|
||||
$this->WhatsappTemplate_model->upsert_template($data);
|
||||
// $saved[] = $data;
|
||||
}
|
||||
|
||||
$this->output
|
||||
->set_content_type('application/json')
|
||||
->set_output(json_encode(['success' => true, 'message' => 'Sinkronisasi selesai']));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user