botman / driver-facebook

BotMan Facebook Messenger Driver
MIT License
71 stars 72 forks source link

INFO: Is the driver supporting NON_PROMOTIONAL_SUBSCRIPTION tag? #79

Open tommiekn opened 5 years ago

tommiekn commented 5 years ago

Hi,

Just wondering if the driver does or will support the NON_PROMOTIONAL_SUBSCRIPTION tag that is required from next year to send subscription messages.

https://developers.facebook.com/docs/messenger-platform/policy/app-to-page-subscriptions/

Thanks

christophrumpel commented 5 years ago

hey @tommiekn, thanks for the info. Right, we need to implement that somehow. I think right now it should be possible by adding the tag with the additionalParameters with say method, which you will need to originate a message.

Actually, I think this is the best solution right now because I can't think of another one. We need to only add it for originating a message and there are dozens of tags available. So it is difficult to bake that into the driver. What do you think @mpociot?

crunck1 commented 5 years ago

hi, i've had the same problem trying to send ISSUE_RESOLUTION tag. I've solved extending the FacebookDriver class,ovverriding buildServicePayload method, using a custom array_merge_recursive_distinct method ([http://php.net/manual/en/function.array-merge-recursive.php#92195]) while merging additonalParameters. This is necessary to replace the default messaging_type ('RESPONSE ') with the requested value: MESSAGE_TAG. Sincerely i didn't run any test but the solution seems to work by now. Let me know if it works for you too.

tommiekn commented 5 years ago

@christophrumpel @mpociot this got implemented in the end or is still open?

Astriel commented 4 years ago

Any updates ?

doantvsp commented 3 years ago

@crunck1 Can you explain, how to override method buildServicePayload in Laravel

sugoireed commented 2 years ago

Anyone having a challenge with this. This is the approach.

 Create a new Class call it FacebookDriverCustom and let it extend FacebookDriver

 Inside it override the buildServicePayload method and customize it to allow you to pass the messaging_type as one of the 
 additional params by commenting it out.

  Optionally you can also just hard code whatever messaging _type you want there as well.

Here is the class

class FacebookDriverCustom extends FacebookDriver { public function buildServicePayload($message, $matchingMessage, $additionalParameters = []) { if ($this->driverEvent) { $payload = $this->driverEvent->getPayload(); if (isset($payload['optin']) && isset($payload['optin']['user_ref'])) { $recipient = ['user_ref' => $payload['optin']['user_ref']]; } else { $recipient = ['id' => $payload['sender']['id']]; } } else { $recipient = ['id' => $matchingMessage->getSender()]; } $parameters = array_merge_recursive([ // 'messaging_type' => self::TYPE_RESPONSE, //Commented out or you can hard code yours here 'recipient' => $recipient, 'message' => [ 'text' => $message, ], ], $additionalParameters); /*