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
428 stars 151 forks source link

message instance retrieval / PSR HTTP message in VerificationRequest #135

Closed doganoo closed 10 months ago

doganoo commented 10 months ago

thank you for this great project!

I have two suggestions/RFC's and would like to find out if this is supported.

  1. public getter for $message in Netflie\WhatsAppCloudApi\Request\MessageRequest:
    public function getMessage(): Message {
        return $this->message;
    }

Background: retrieving the message instance enables to log what is sent to the API.

  1. letting Netflie\WhatsAppCloudApi\WebHook\VerificationRequest return Psr\Http\Message\ResponseInterface instead of emitting the HTTP codes.
public function validate(array $payload): ResponseInterface
    {
        $mode = $payload['hub_mode'] ?? null;
        $token = $payload['hub_verify_token'] ?? null;
        $challenge = $payload['hub_challenge'] ?? '';

        if ('subscribe' !== $mode || $token !== $this->verify_token) {
            return new EmptyResponse(403);
        }

        return new TextResponse($challenge, 200);
    }

the EmptyResponse and TextResponse classes have to be implemented.

I would be ready to implement this if it is welcome. Please let me know what you think.

aalbarca commented 10 months ago

Hi @doganoo your suggestions are always welcome.

  1. I'm not sure. I think this would weaken the encapsulation of the class and the benefits are unclear.

I think that clients what consume this library should be able to write logs of their messages without knowing internal details of how the library is built or its objects.

  1. It seems like a fantastic idea to me, but modifying the signature of a method would cause a break in the current major version and this would force a major version to be released. But we still do not have significant changes that justify this version jump.

Maybe I could create a dev-3.0 branch and integrate the change there.