expo / expo

An open-source framework for making universal native apps with React. Expo runs on Android, iOS, and the web.
https://docs.expo.dev
MIT License
31.24k stars 4.95k forks source link

Expo notification with FCM : No scope key found in notification #15158

Closed khelifioussama closed 2 years ago

khelifioussama commented 2 years ago

Summary

FCM notification are not shown in device ,

Managed or bare workflow? If you have made manual changes inside of the ios/ or android/ directories in your project, the answer is bare!

managed

What platform(s) does this occur on?

Android

Package versions

No response

Environment

Expo CLI 4.13.0 environment info: System: OS: Windows 10 10.0.19042 Binaries: Node: 14.17.1 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.11 - ~\AppData\Roaming\npm\yarn.CMD npm: 6.14.13 - C:\Program Files\nodejs\npm.CMD IDEs: Android Studio: Version 2020.3.0.0 AI-203.7717.56.2031.7784292 npmPackages: @expo/webpack-config: ^0.16.2 => 0.16.7 expo: ^43.0.0 => 43.0.2 react: 17.0.1 => 17.0.1 react-dom: 17.0.1 => 17.0.1 react-native: 0.64.3 => 0.64.3 react-native-web: 0.17.1 => 0.17.1 Expo Workflow: managed

Reproducible demo or steps to reproduce from a blank project

Working with FCM notification server side and expo-notification device side , I did use expo-notification documentation but no notification sent to device , so I used android studio to debug the APK and I have this message for every received notification : E/expo-notifications: No scope key found in notification . any solution Please

Stacktrace (if a crash is involved)

No response

brentvatne commented 2 years ago

you need to follow the payload format specified in https://docs.expo.dev/push-notifications/sending-notifications-custom/#fcm-server

khelifioussama commented 2 years ago

as Payload I am using this : const message = { data: { title: ${title}, message: ${body}, // ⚠️ Notice the schema of this payload is different // than that of Firebase SDK. What is there called "body" // here is a "message". For more info see: // https://docs.expo.dev/versions/latest/sdk/notifications/#android-push-notification-payload-specification

  // ⚠️ As per Android payload format specified above, the
  body: JSON.stringify(data.payload), // additional "data" should be placed under "body" key.
},

}; with firebase-admin :

admin .messaging() .sendToDevice(pushToken, message, notification_options) .then((response) => { }) .catch((error) => { });

brentvatne commented 2 years ago

you need to provide the experienceId as referenced in https://docs.expo.dev/push-notifications/sending-notifications-custom/#fcm-server

khelifioussama commented 2 years ago

@brentvatne I have the same issue until now I am using expo notification as listener I try to send notification throw PostMan with Body : { "to" : MYKEY", "priority": "normal", "data": { "experienceId": "MY EXPERIENCE ID", "title": "Hello", "message": "Test Message" } } and with Header contain : Content-Type : application/json and Authorization : key= MYKEY and I got always the same error : E/expo-notifications: No scope key found in notification

randomjunk commented 2 years ago

The message format you need to send to FCM appears to have changed after this PR: https://github.com/expo/expo/pull/12964/files#diff-5baa817040e79cc34458002f16536c38b1836bf3baf3b541b72b0b96beaee011R48 (Expo 43 I think)

experienceId -> scopeKey

It's not clear to me that this was deliberate.

jezzgoodwin commented 2 years ago

@randomjunk thank you for this information. I can now send Android notifications to apps built with Expo 43+

wschurman commented 2 years ago

Sorry for the thrash. The change from experienceId to scopeKey was deliberate, and I forgot to update this documentation. Will make the update now.