Untitled

 avatar
unknown
plain_text
3 years ago
2.3 kB
2
Indexable
 public function bulkSendMessagesCustomer(){
        // Load data customer yang sudah teregistrasi
        $clientId = 7; //id unique di table client_device
        $getCustomers = $this->clientDevice->loadGetCustomerByClientId($clientId);
        $getCustomers = json_decode($getCustomers);
        $getCustomersData = $getCustomers->data;

        // Foreach data customer 
        foreach ($getCustomersData as $gc) {
            $loadNotif = $this->fx->loadAutoreplySystem(1);
            $provinceId = $gc->customer_province_id;

            $getProvinceCustomer = $this->data->get("provinces", "WHERE id = $provinceId");

            $replace_message = [
                'nama' => $gc->customer_name,
                'province' => $getProvinceCustomer->name
            ];

            $message = $loadNotif->message_body;
            if(isset($replace_message))
            $message = preg_replace_callback('/{{(\w+)}}/', function($match) use($replace_message) {
                return $replace_message[$match[1]];
            }, $message );

            $buttons = array(
                "button_1_id" => $loadNotif->button_1_id,
                "button_1_label" => $loadNotif->button_1_label,
                "button_2_id" => $loadNotif->button_2_id,
                "button_2_label" => $loadNotif->button_2_label,
                "button_3_id" => $loadNotif->button_3_id,
                "button_3_label" => $loadNotif->button_3_label
            );

            $paramSend = [
                "access_key"        => $gc->client_device_access_key,
                'sender'            => $gc->client_device_phone,
                "receiver"          => $gc->customer_phone,
                "message_body"      => $message,
                'buttons'           => $buttons,
                'button_1_id'       => $loadNotif->button_1_id,
                'button_1_label'    => $loadNotif->button_1_label,
                "message_type"      => $loadNotif->message_type,
                "device_name"       => $gc->device_name,
            ];
                
            $response = $this->fx->sendApi($gc->device_url_server . '/chat/sendv2', $paramSend);
            // Buat interval untuk setiap message
            $interval = rand(3, 5);
            sleep($interval);
        }

    }
Editor is loading...