driver-facebook icon indicating copy to clipboard operation
driver-facebook copied to clipboard

INFO: Is the driver supporting NON_PROMOTIONAL_SUBSCRIPTION tag?

Open tommiekn opened this issue 6 years ago • 6 comments

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

tommiekn avatar Sep 19 '18 16:09 tommiekn

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?

christophrumpel avatar Oct 03 '18 06:10 christophrumpel

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.

crunck1 avatar Dec 13 '18 22:12 crunck1

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

tommiekn avatar Jan 17 '19 15:01 tommiekn

Any updates ?

Astriel avatar Mar 05 '20 14:03 Astriel

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

doantvsp avatar Oct 22 '20 10:10 doantvsp

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); /* * If we send a Question with buttons, ignore * the text and append the question. */ if ($message instanceof Question) { $parameters['message'] = $this->convertQuestion($message); } elseif (is_object($message) && in_array(get_class($message), $this->templates)) { $parameters['message'] = $message->toArray(); } elseif ($message instanceof OutgoingMessage) { $attachment = $message->getAttachment(); if (! is_null($attachment) && in_array(get_class($attachment), $this->supportedAttachments)) { $attachmentType = strtolower(basename(str_replace('\', '/', get_class($attachment)))); unset($parameters['message']['text']); $parameters['message']['attachment'] = [ 'type' => $attachmentType, 'payload' => [ 'is_reusable' => $attachment->getExtras('is_reusable') ?? false, 'url' => $attachment->getUrl(), ], ]; } else { $parameters['message']['text'] = $message->getText(); } }

$parameters['access_token'] = $this->config->get('token'); return $parameters; } }

sugoireed avatar Aug 26 '21 08:08 sugoireed