infobip / infobip-api-php-client

Infobip API client library in PHP using composer.
https://www.infobip.com/docs/api
MIT License
80 stars 68 forks source link

More detailed changelogs or upgrade guides. #51

Closed daniel-swordfish closed 1 year ago

daniel-swordfish commented 1 year ago

@ib-fsrnec can we possibly get more detailed changelogs or upgrade guides 5.0.0 and future major releases? The changelog simply says there are breaking changes then just links to the documentation. This is not very helpful.

ibirogar commented 1 year ago

Hi.

In the case of 5.0.0, the changelog states: "Fully refactored codebase using Symfony components".

For this particular version it means that the entire codebase is affected; meaning models, API classes, utility classes, object serializer, configuration. Also, new ones were introduced like custom normalizers.

Regarding API classes and models, this mostly means validation via attributes and strict typing throughout.

daniel-swordfish commented 1 year ago

So I am trying to upgrade by using the code as documentation.

I have updated my function to create templates as follows:

    private function getTemplateHeaderApiData($header)
    {
        return match ($header['format'] ?? null) {
            WhatsAppType::TEXT => new WhatsAppTextHeaderApiData(
                text: $header['text'],
                example: $header['example'] ?? null
            ),
            WhatsAppType::DOCUMENT => new WhatsAppDocumentHeaderApiData(
            ),
            WhatsAppType::IMAGE => new WhatsAppImageHeaderApiData(
            ),
            WhatsAppType::VIDEO => new WhatsAppVideoHeaderApiData(
            ),
            WhatsAppType::LOCATION => new WhatsAppLocationHeaderApiData(),
            default => null,
        };
    }

    public function createInfobipTemplate(WhatsappTemplate $template): void
    {
        // Create template on infobip
        $headerApiData = $this->getTemplateHeaderApiData($template->structure['header']);

        $request = new WhatsAppTemplatePublicApiRequest(
            name: $template->name,
            language: $template->language,
            category: $template->category,
            structure: new WhatsAppTemplateStructureApiData(
                body: new WhatsAppBodyApiData(
                    text: $template->structure['body']['text'] ?? null,
                    examples: $template->structure['body']['examples'] ?? null,
                ),
                header: $headerApiData,
                footer: new WhatsAppFooterApiData(
                    text: $template->structure['footer']['text'] ?? null,
                ),
                buttons: $template->structure['buttons'] ?? null,
                type: $template->structure['type'] ?? null,
            ),
        );

        $response = $this->api?->createWhatsAppTemplate($this->config['number'], $request);
    }

I am attempting to test the changes with a template where $template->structure is a associative php array made from the following json

{
  "header": {
    "format": "TEXT",
    "text": "test"
  },
  "body": {
    "text": "Test"
  },
  "footer": {
    "text": "test"
  },
  "buttons": [
    {
      "text": "test",
      "type": "QUICK_REPLY"
    },
    {
      "text": "test",
      "type": "QUICK_REPLY"
    },
    {
      "text": "test",
      "type": "QUICK_REPLY"
    }
  ]
}

However when I send the request I get the following error

{
    "requestError": {
        "serviceException": {
            "messageId": "BAD_REQUEST",
            "text": "Error occurred in communication with external provider"
        }
    }
}

@ibirogar Am I using the WhatsAppTemplatePublicApiRequest class wrong or is there a bug in the library?

daniel-swordfish commented 1 year ago

The problem ended up being that the text for my quick reply buttons were the same.