# Push

Set up push notifications.

## Firebase token

To use **push notifications** with this SDK, you have to provide **Firebase token** and upload it to our Sinch Panel.

Note:
Push notification works via Firebase service, so you need to make sure we have your server token.

### Initialization SDK with push notification token

Below is an example of intializing the SDK with a push notification token:

```kotlin
FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->

    val options = SinchInitializationOptions(null)
    if (task.isSuccessful) {
        options.pushDeviceToken = task.result
    }
    SinchChatSDK.initialize(applicationContext, options)
}
```

### Set up Firebase Messaging service

To set up the Firebase Messsaging service:

1. Add these dependencies to your app using the `build.gradle` file:

```kotlin
implementation platform('com.google.firebase:firebase-bom:{version}')
implementation 'com.google.firebase:firebase-messaging:{version}'
implementation 'com.google.firebase:firebase-analytics-ktx'
```
2. The `AndroidManifest.xml` file adds a new service for push notifications;

```kotlin
<service
    android:name=".AppFirebaseMessagingService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>
```
3. Create file called `AppFirebaseMessagingService` to match `android:name`. Copy the code below and paste it into the file:

```kotlin
class AppFirebaseMessagingService : FirebaseMessagingService() {

    override fun onNewToken(p0: String) {
        super.onNewToken(p0)
        SinchChatSDK.push.onNewToken(p0)
    }

    override fun onMessageReceived(p0: RemoteMessage) {
        super.onMessageReceived(p0)
        if (SinchChatSDK.push.onMessageReceived(p0)) {
            // This notification belongs to SinchChatSDK.
            return
        }
    }
}
```


### Start conversation when starting the Chat.

If you want to initialize a conversation for your user, you must start the chat with the following option shown in the example below:

```kotlin
val options = SinchStartChatOptions(shouldInitializeConversation = true)
SinchChatSDK.chat.start(this, options)
```

#### Troubleshooting

You may encounter issues with building your application. These may be related to Protobuf dependencies.

To troubleshoot, paste these lines in the `android {}` section in `build.gradle`:

```kotlin
android {
    ...

    configurations {
        implementation.exclude module:'protolite-well-known-types'
        implementation.exclude module:'protobuf-lite'
    }
}
```