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

🐛 Bug Report: messaging.createPush Function Fails with Optional Parameters in Node.js Cloud Function #8287

Closed
2 tasks done
NeKoFu opened this issue Jun 19, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@NeKoFu
Copy link

NeKoFu commented Jun 19, 2024

👟 Reproduction steps

I'm encountering an issue when using the messaging.createPush function within a Node.js cloud function. Specifically, the function fails when optional parameters are set to null.

Steps to Reproduce:

  1. Use the following code with null for optional parameters:
message = await messaging.createPush(
    ID.unique(),            // messageId
    title,                  // title
    body,                   // body
    [],                     // topics (optional)
    users || [],            // users (optional)
    targets || [],          // targets
    data || {},             // data
    null,                   // action (optional)
    null,                   // image (optional)
    null,                   // icon (optional)
    sound,                  // sound (optional)
    null,                   // color (optional)
    null,                   // tag (optional)
    null,                   // badge (optional)
    false,                  // draft (optional)
    null                    // scheduledAt (optional)
);
  1. Replace null with an empty string '':
message = await messaging.createPush(
    ID.unique(),            // messageId
    title,                  // title
    body,                   // body
    [],                     // topics (optional)
    users || [],            // users (optional)
    targets || [],          // targets
    data || {},             // data
    '',                     // action (optional)
    '',                     // image (optional)
    '',                     // icon (optional)
    sound,                  // sound (optional)
    '',                     // color (optional)
    '',                     // tag (optional)
    '',                     // badge (optional)
    false,                  // draft (optional)
    ''                      // scheduledAt (optional)
);

👍 Expected behavior

Works without throwing any errors about optional parameters 😁

👎 Actual Behavior

  1. With null the following error is logged in the Appwrite container:

2024-06-19 01:44:29 [Error] Method: POST
2024-06-19 01:44:29 [Error] URL: /v1/messaging/messages/push
2024-06-19 01:44:29 [Error] Type: TypeError
2024-06-19 01:44:29 [Error] Message: {closure}(): Argument #8 ($action) must be of type string, null given, called in /usr/src/code/vendor/utopia-php/framework/src/App.php on line 531
2024-06-19 01:44:29 [Error] File: /usr/src/code/app/controllers/api/messaging.php
2024-06-19 01:44:29 [Error] Line: 2876

  1. With empty string '' the following error is logged:

2024-06-19 01:31:10 [Error] Method: POST
2024-06-19 01:31:10 [Error] URL: /v1/messaging/messages/push
2024-06-19 01:31:10 [Error] Type: Utopia\Exception
2024-06-19 01:31:10 [Error] Message: Invalid action param: Value must be a valid string and at least 1 chars and no longer than 256 chars
2024-06-19 01:31:10 [Error] File: /usr/src/code/vendor/utopia-php/framework/src/App.php
2024-06-19 01:31:10 [Error] Line: 774

It seems that the issue originates from the declaration of the following function :
app/controllers/api/messaging.php

The optional character is missing
string $action 👉 ?string $action

🎲 Appwrite version

Version 1.5.x

💻 Operating system

Linux

🧱 Your Environment

Appwrite Version 1.5.7

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

@NeKoFu NeKoFu added the bug Something isn't working label Jun 19, 2024
@NeKoFu
Copy link
Author

NeKoFu commented Jun 19, 2024

appwrite libs check for undefined 🤔

so the call below works fine:

message = await messaging.createPush(
            ID.unique(),            // messageId
            title,                  // title
            body,                   // body
            [],                     // topics (optional)
            users || [],            // users (optional)
            targets || [],          // targets
            data || {},             // data
            undefined,              // action (optional)
            undefined,              // image (optional)
            undefined,              // icon (optional)
            sound,                  // sound (optional)
            undefined,              // color (optional)
            undefined,              // tag (optional)
            undefined,              // badge (optional)
            false,                  // draft (optional)
            undefined               // scheduledAt (optional)
        );

@NeKoFu NeKoFu closed this as completed Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant