-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Pinpoint JSON Body Isn't JSON #2808
Comments
Hi @aronduby, sorry to hear about your issues. You need to specify the GCMMessage parameter under the MessageConfiguration parameter as follow: $pinpointClient->sendMessages([
'ApplicationId' => self::getPinpointProjectId(),
'MessageRequest' => [
'MessageConfiguration' => [
'GCMMessage' => [
'Data' => [
'greeting' => 'Hello, how are you?',
'target' => 'World',
'notification_hash' => 'aron-TestNotification-18-65412f684d1373.42976821'
]
]
]
],
]); Could you please try with the previous code and confirm if the issue still persists? Thanks! |
Apologies, that was a mistake on my behalf when trying to get to the smallest reproducible code without a lot of project related stuff. I have confirmed that it is sent under the // in the notification class
public function toPinpointPush($notifiable): array {
$msg = parent::toPinpointPush($notifiable);
$msg['Data'] = [
'target' => 'World',
'greeting' => 'Hello',
];
return $msg;
} // in my sending class
$messageRequest['Endpoints'][$endpoint['pinpoint']['endpoint_id']] = [];
$gcmMessage = $notification->toPinpointPush($notifiable);
// Pinpoint won't send the url if it doesn't have an action of URL, so make sure it has that
if (array_key_exists('Url', $gcmMessage) && !array_key_exists('Action', $gcmMessage)) {
$gcmMessage['Action'] = 'URL';
}
// add the notification hash into the data
$gcmMessage['Data'] = array_merge($gcmMessage['Data'] ?? [], ['notification_hash' => $notificationHash]);
// Data does not work right - so we are going to dance around it
// https://github.com/aws/aws-sdk-php/issues/2808
// $gcmMessage['Data'] = [
// '::JSON::' => json_encode($gcmMessage['Data'])
// ];
$messageRequest['MessageConfiguration']['GCMMessage'] = $gcmMessage;
// ...
$pinpointClient = self::getPinpointClient();
$results = $pinpointClient->sendMessages([
'ApplicationId' => self::getPinpointProjectId(),
'MessageRequest' => $messageRequest
]); Then on the front end I have the following code receiving the message through FCM onMessage(messaging, (payload) => {
console.log('Message received. ', payload);
}); |
@aronduby thanks for clarifying. I have opened a ticket against the service team to better investigate this. I will get back to you once I get an answer from them. Thanks! |
V1109454414 |
Hi @aronduby, I have gotten confirmation from the service that this has been fixed now. Can you please check and confirm is working for you? Thanks! |
Closing for now. Please reopen if the issue still persists or open a new issue for anything else that we can help with. Thanks! |
|
@yenfryherrerafeliz I have confirmed this is working as expected for me now, thank you! |
Describe the bug
I'm using Pinpoint to send web push notifications through FCM. When I set the GCMMessage.Data parameter in sendMessage it comes through to the frontend as pinpoint.jsonBody but it's not JSON encoded.
Expected Behavior
It would be fully json encoded and I could just call JSON.parse and it would work
Current Behavior
It comes through not json encoded
Reproduction Steps
Possible Solution
No response
Additional Information/Context
No response
SDK version used
3.261.14
Environment details (Version of PHP (
php -v
)? OS name and version, etc.)php 8.2 Ubuntu 20.04.6 LTS
The text was updated successfully, but these errors were encountered: