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

Close conversation screen #35

Open
Esteban-ortega-roy opened this issue Nov 27, 2023 · 6 comments
Open

Close conversation screen #35

Esteban-ortega-roy opened this issue Nov 27, 2023 · 6 comments
Labels
enhancement New feature or request pinned

Comments

@Esteban-ortega-roy
Copy link

Esteban-ortega-roy commented Nov 27, 2023

This is not a bug but a question:

Context: If the app is sent to background and opened it again X minutes later, the user has to authenticate/login again, just like most baking apps.

Problem: If the conversation was opened before the app was sent to background, when the app comes to foreground again, the conversation is visible.

Goal: Programmatically close the conversation when the app is sent to background.

I've tried using "reset" to invalidate the instance but that only makes the conversation unresponsive (can't send messages) but it is still visible/readable.

  • Is there any way to close the conversation programmatically?
  • If not, is there any way to implement that functionality? I've been playing with the example project and rootController.dismiss(animated: true, completion: nil), and it seems to work, but I have no idea about Swift and I don't even know how we could do this for Android too.
@leegeunhyeok
Copy link
Owner

Hi, @Esteban-ortega-roy.

  • Q1. Is there any way to close the conversation programmatically?
    • A1. No, the Zendesk SDK does not implement the feature to close conversation view.
  • Q2. If not, is there any way to implement that functionality?
    • A1. iOS: need to implement bridge method for call from js runtime / Android isn't possible because we can't access to the conversation activity.

@leegeunhyeok leegeunhyeok added enhancement New feature or request question Further information is requested and removed enhancement New feature or request labels Nov 30, 2023
@Esteban-ortega-roy
Copy link
Author

Esteban-ortega-roy commented Nov 30, 2023

Thank you for your answer @leegeunhyeok

A2. iOS: need to implement bridge method for call from js runtime / Android isn't possible because we can't access to the conversation activity.

Yes, that's what I tried using this example repo: bridge + native code to rootController.dimiss. It seems to work

A1. No, the Zendesk SDK does not implement the feature to close conversation view.

I have an open ticket with Zendesk talking about this. So far the only workaround they gave me is what we've discussed above about iOS, I'm still waiting for workaround for Android. I also asked them if it would be possible that they include this feature in their SDKs, for me it makes sense to have a ".closeMessaging", just as they have ".showMessaging".

I'll update this ticket with the information I got from them, just in case it helps to someone else.

@leegeunhyeok
Copy link
Owner

Thanks! I'll follow up too.

@leegeunhyeok leegeunhyeok added enhancement New feature or request pinned and removed question Further information is requested labels Nov 30, 2023
@pwfcurry
Copy link

pwfcurry commented Jan 17, 2024

Hi @leegeunhyeok thank you for creating this package! Did you or @Esteban-ortega-roy hear back from Zendesk?

@Esteban-ortega-roy
Copy link
Author

@pwfcurry Not yet.
I'm waiting for them to confirm if something like ".closeMessaging" is in their roadmap.
As soon as I know something else I'll post it here

@mfds
Copy link
Contributor

mfds commented Feb 22, 2024

Hi! Here's what we did to handle the "closeMessaging" behaviour on Android

Unfortunately, having a "closeMessagingView" method might not be the best solution here as that would require the activity to run/call that code. Zendesk chat runs on a separate Activity, so we need to work around that.

We have a similar use case where the application needs to close the chat window if the app has been in background for too long.

Having tried a few things, we eventually settled for a new custom native module that listens to the Activity changes:

class ActivityLifecycleListener : Application.ActivityLifecycleCallbacks {
  override fun onActivityResumed(activity: Activity) {
    if (activity.javaClass.simpleName != "MainActivity" && areConditionsMet()) {
      activity.finish()
    }
    trackActivityResumed(activity.javaClass.simpleName);  
  }

  override fun onActivityStopped(activity: Activity) {
      trackActivityStopped(activity.javaClass.simpleName);  
  }

(just an example with the gist of what we did, this is not actual code). Remember to override all methods within this public interface.

Last thing to do is to register the listener.
Expo native modules can call a method on module creation that has access to appContext so you can do things like:

private fun registerLifecycleListener() {
  val applicationContext = appContext.reactContext?.applicationContext as? Application
  applicationContext?.registerActivityLifecycleCallbacks(ActivityLifecycleListener())
}

(so you would call this within the OnCreate method)

or, if you're patching the react-native-zendesk-messaging package (e.g. using patch-package) you can use init on the ZendeskMessagingModule class like so:

init {
  val applicationContext = reactContext.applicationContext as? Application
  applicationContext?.registerActivityLifecycleCallbacks(ActivityLifecycleListener())
}

Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pinned
Projects
None yet
Development

No branches or pull requests

4 participants