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

Pinpoint JSON Body Isn't JSON #2808

Closed
aronduby opened this issue Oct 31, 2023 · 8 comments
Closed

Pinpoint JSON Body Isn't JSON #2808

aronduby opened this issue Oct 31, 2023 · 8 comments
Assignees
Labels
bug This issue is a bug. p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@aronduby
Copy link

aronduby commented Oct 31, 2023

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.

pinpoint.jsonBody:  ""{greeting=Hello, how are you?, notification_hash=aron-TestNotification-18-65412f684d1373.42976821, target=World}""

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

<?php
$pinpointClient->sendMessages([
    'ApplicationId' => self::getPinpointProjectId(),
    'MessageRequest' => [
        'GCMMessage' => [
            'Data' => [
                'greeting' => 'Hello, how are you?',
                'target' => 'World',
                'notification_hash' => 'aron-TestNotification-18-65412f684d1373.42976821'
            ]
        ]
    ],
]);

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

@aronduby aronduby added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 31, 2023
@yenfryherrerafeliz yenfryherrerafeliz self-assigned this Oct 31, 2023
@yenfryherrerafeliz yenfryherrerafeliz added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Nov 6, 2023
@yenfryherrerafeliz
Copy link
Contributor

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!

@yenfryherrerafeliz yenfryherrerafeliz added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p2 This is a standard priority issue and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Nov 13, 2023
@aronduby
Copy link
Author

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 MessageConfiguration key.

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

Which results in this in the console:
image

@yenfryherrerafeliz yenfryherrerafeliz added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Nov 13, 2023
@yenfryherrerafeliz
Copy link
Contributor

@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!

@yenfryherrerafeliz
Copy link
Contributor

V1109454414

@yenfryherrerafeliz
Copy link
Contributor

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!

@yenfryherrerafeliz yenfryherrerafeliz added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Dec 19, 2023
@yenfryherrerafeliz
Copy link
Contributor

Closing for now. Please reopen if the issue still persists or open a new issue for anything else that we can help with.

Thanks!

Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@aronduby
Copy link
Author

@yenfryherrerafeliz I have confirmed this is working as expected for me now, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants