netflie / whatsapp-cloud-api

The first PHP API to send and receive messages using a cloud-hosted version of the WhatsApp Business Platform
https://netflie.es/portfolio/whatsapp-business-cloud-api-php-sdk/
MIT License
484 stars 177 forks source link

Fetch Business templates #199

Closed aindot closed 4 months ago

aindot commented 4 months ago

Hello, I'm using https://github.com/joelbutcher/laravel-facebook-graph:

composer require joelbutcher/laravel-facebook-graph
use JoelButcher\Facebook\Facebook;

        $facebook = new Facebook([
            'app_id' => config('app.app_id'), // App Id
            'app_secret' => config('app.app_secret'), // App secret
            'default_graph_version' => config('app.graph_version'), // Your graph version
            'default_access_token' => config('app.w_token'), // Your system account access token
        ]);

        $w_buss_id = config('app.w_buss_id'); // WhatsApp business ID

        // fields that we are going to request from Meta API.
        $fields = [
            'id',
            'name',
            'status',
            'language',
            'category',
            'rejected_reason',
            'quality_score',
            'components',
            'health_status',
        ];
        $fields = implode(',', $fields);

        $feed = $facebook->get("$w_buss_id/message_templates?fields=$fields&limit=10");
        $feed = $feed->getGraphEdge();

        // loop over the feed and save the data to your model
        while ($feed != null) {
            foreach ($feed->asArray() as $data) {
                WhatsAppTemplate::query()->create([
                    'template_id' => $data['id'],
                    'name' => $data['name'],
                    'category' => $data['category'],
                    'status' => $data['status'],
                    'language' => $data['language'],
                    'rejected_reason' => $data['rejected_reason'],
                    'quality_score' => $data['quality_score']['score'],
                    'quality_score_date' => $data['quality_score']['date'],
                    'components' => $data['components'],
                    'health_status_payload' => [$data['health_status']], // include it inside an array as other components
                ]);
            }

            $feed = $facebook->next($feed);
        }

Regards,

aalbarca commented 4 months ago

Hi @aindot wich bug are you reporting?

aindot commented 4 months ago

Hello, @aalbarca I'm just dropping a tip, and If I have some other tips were should I put them.

aalbarca commented 4 months ago

Please, open a PR with the changes.

Tips are also welcome but in the Discussion forum not in this channel because is just to report bugs.

Thanks.