GetStream / stream-chat-flutter

Flutter Chat SDK - Build your own chat app experience using Dart, Flutter and the Stream Chat Messaging API.
https://getstream.io/chat/sdk/flutter/
Other
930 stars 342 forks source link

Push notification not working #328

Closed haohaowasky closed 3 years ago

haohaowasky commented 3 years ago

I was following with https://getstream.io/chat/docs/flutter-dart/push_android/?language=dart&q=mention

to set up chat notification given we already have the chatting feature setup.

Issues are:

  1. Not sure why some of the Java/Kotin code are there in the tutorial and was no such methods in the flutter SDK
  2. The only method I found from the flutter SDK is the addDevice, so I've enabled that.

However, when I tried stream chat:push:test it gives me error with message: publishing the message failed. code = "200"; error = "InvalidRegistration"

Any idea on what's missing? I'm only testing on Android for now.

gz#10133

imtoori commented 3 years ago

Hi @haohaowasky that guide is related to android and not flutter

we're writing a detailed guide on how to set up notifications using flutter, but it's not hard

what package are you using for notifications on flutter?

haohaowasky commented 3 years ago

So I'm using stream_chat_flutter.dart

And I see only one method here related to notification which is addDevice. And I have added to that in my code, however, as I said before it seems like some registration issue happening from firebase.

imtoori commented 3 years ago

I suggest you take a look at this package to configure notifications https://pub.dev/packages/flutter_apns Our package doesn't handle notifications as it's an external service in a flutter app

haohaowasky commented 3 years ago

So in our end, our requirement is user getting a notification when there is a message received. Pretty much the same feature you guys mentioned at https://getstream.io/chat/docs/flutter-dart/push_introduction/?language=dart&q=mention

The problem is I haven't seen the methods in Flutter SDK

imtoori commented 3 years ago

@haohaowasky the only method we provide is addDevice that you should call once the token of the push notification service is available To set up notifications you should use a package like flutter_apns (https://pub.dev/packages/flutter_apns) as you would do for any other app The difference is that you would also use addDevice to send us the notification token so that we can send you notifications

luantrasel commented 3 years ago

@haohaowasky you can also configure a webhook endpoint on GetStream portal and deal with the notifications youself. I did this way because flutter_apns is incompatible with other firebase libraries that I was already using

imtoori commented 3 years ago

I can confirm firebase_messaging is enough to set up push notifications just have to keep in mind that you have to configure only android in Stream dashboard and always use PushProvider.firebase in the client.addDevice call

it's kind of a workaround, but it works well

I'll close this in favor of #195 to keep track of push notifications I'll update that issue once I finish writing docs

Aimen-Zelaci commented 3 years ago

@imtoori I have configured push notification successfully on a flutter app. When I use the CLI test it works and I receive the notification normally. But, when I send a message from the emulator to my device I don't receive the notification nor on the notification logs.

imtoori commented 3 years ago

@Aimen-Zelaci can you check that you're respecting the logic you can read here? https://getstream.io/chat/docs/flutter-dart/push_introduction/?language=dart

Aimen-Zelaci commented 3 years ago

@imtoori Thank you very much for your quick response. Yes, I am quite sure.

stream chat:push:test --user_id 'user_123' this works and sends the notification to my device and I also receive it using: FirebaseMessaging().configure().

But not when I send a message.

imtoori commented 3 years ago

are you sure the client is not connected? you should put the app in background and wait for the client to disconnect if the user is connected (even on other devices) the notification won't be sent

shodgetts commented 3 years ago

Hello 👋 Stephen here from the Stream Customer Success department. There could be a few things going wrong here, and in order to properly debug with you, we'd like to know a few things about your app and users. Could you please email support@getstream.io with your app_id, channel_id, and user_id's who are affected. From there, we can make a few checks. Thank you 🙏

Aimen-Zelaci commented 3 years ago

@imtoori Yes, I am. I have tried both:

  1. Not calling client.connectUser
  2. Called client.connectUser and put the app in the background.
Aimen-Zelaci commented 3 years ago

@imtoori @shodgetts My users were not being added as members, as I thought they were. I'd changed from a 'Messaging' channel to a 'Livestream channel and I believed that members are added as soon as I call channel.watch(), just because users were able to send messages, even without being added as members. After updating channel members, I was finally able to receive FCM notifications. Thank you very much for this quick and interactive response.