Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INFO: Is the driver supporting NON_PROMOTIONAL_SUBSCRIPTION tag? #79

Open
tommiekn opened this issue Sep 19, 2018 · 6 comments
Open

INFO: Is the driver supporting NON_PROMOTIONAL_SUBSCRIPTION tag? #79

tommiekn opened this issue Sep 19, 2018 · 6 comments

Comments

@tommiekn
Copy link

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
Copy link

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
Copy link

crunck1 commented Dec 13, 2018

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
Copy link
Author

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

@Astriel
Copy link

Astriel commented Mar 5, 2020

Any updates ?

@doantvsp
Copy link

doantvsp commented Oct 22, 2020

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

@sugoireed
Copy link

sugoireed commented Aug 26, 2021

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;
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants