appleboy / gorush

A push notification server written in Go (Golang).
MIT License
7.84k stars 829 forks source link

error when send notification using FCM Http v1 #788

Closed dongphh closed 1 week ago

dongphh commented 1 week ago

Hi @appleboy

I had test send to Android and IOS notification using gorush setup on docker.

I check log and see some message send error for IOS

{"level":"error","msg":"{\"type\":\"failed-push\",\"platform\":\"android\",\"token\":\"....-PPv2HlZKzSx7ZFSG\",\"message\":\"(message redacted)\",\"error\":\"Requested entity was not found.\"}","time":"2024-06-21T02:19:16Z"}
{"level":"error","msg":"{\"type\":\"failed-push\",\"platform\":\"android\",\"token\":\"......gEENv5z2WoSp4ROean6kahLVISC2rIbgyR4VIMl9GsEF9fGSwiwMt0UK94\",\"message\":\"(message redacted)\",\"error\":\"Internal error encountered.\"}","time":"2024-06-21T02:20:05Z"}

Request like this

{
  "notifications": [
    {
      "tokens": [
        "TOKEN"
      ],
      "platform": 2,
      "title": "Title",
      "message": "notice",
      "data": {
        "id": "40007399",
        "isLogin": "Y",
        "messagetype": "HTML",
        "data_extend": ""
      },
      "sound": {
        "name": "default",
        "critical": 1,
        "volume": 10
      }
    }
  ]
}

What is the cause of this error? and how to fix it?

And IOS not play sound when received message Thanks

obuzyig commented 1 week ago

@dongphh you might be getting "Requested entity was not found." since the client token is not an existing / registered token at the FCM. Platform seems to be set FCM in your request example, however, there may be some IOS specified fields as well.

appleboy commented 1 week ago

I will take it and test your input.

appleboy commented 1 week ago

Can you get the notification data with title, message, and custom data payload but miss the sound with iOS? Right?

appleboy commented 1 week ago

@obuzyig Please update the request body as below: volume must be in the interval [0, 1]

{
  "notifications": [
    {
      "tokens": [
        "ftc3Q_b9ny_zfRyEIvs6gC:APA91bELvcQlOGnErWfZY5GWgVTi2SMZ41rGs5mIa_BhUFxcpaumYaTpXX-6eQ5EIxIg0t4-ws35eVOcVz08rcnGp9hH-_JJACd8T5W47P4vAH0AZYnCOlQ-3Hqq3ygnTWeSKZX9WZip"
      ],
      "platform": 2,
      "title": "Title",
      "message": "notice",
      "data": {
        "id": "40007399",
        "isLogin": "Y",
        "messagetype": "HTML",
        "data_extend": ""
      },
      "apns": {
        "payload": {
          "aps": {
            "sound": {
              "name": "default",
              "critical": 1,
              "volume": 0.1
            }
          }
        }
      }
    }
  ]
}
obuzyig commented 1 week ago

@appleboy I tagged @dongphh to avoid any misdirection. It was their question. Thank you.

@obuzyig Please update the request body as below: volume must be in the interval [0, 1]

dongphh commented 1 week ago

Can you get the notification data with title, message, and custom data payload but miss the sound with iOS? Right?

Thanks for your help. It work ok