driver-facebook
driver-facebook copied to clipboard
INFO: Is the driver supporting NON_PROMOTIONAL_SUBSCRIPTION tag?
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
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?
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.
@christophrumpel @mpociot this got implemented in the end or is still open?
Any updates ?
@crunck1 Can you explain, how to override method buildServicePayload in Laravel
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; } }