3

I have implemented agent live availability according to documentation. Problem is according to documentation it would land in OnResult method but every time response is landed in OnCompleted method, where I am unable to retrieve agent status from async variable. Please Guide me if I am missing something or how to get live agent availability from OnCompleted.

My code (called within HomeFragment)

private void setupChatButton() {
        try {


            // Build a configuration object
            ChatConfiguration chatConfiguration =
                    new ChatConfiguration.Builder(ORG_ID, BUTTON_ID,
                            DEPLOYMENT_ID, LIVE_AGENT_POD)
                            .build();


            // Create an agent availability client
            AgentAvailabilityClient client = ChatCore.configureAgentAvailability(chatConfiguration);

            // Check agent availability
            client.check().onResult((async, state) -> {

                switch (state.getStatus()) {
                    case AgentsAvailable: {
//                            Toast.makeText(context, "Available  Chat", Toast.LENGTH_LONG).show();
                        isAgentAvailable = true;
                        fabChat.setBackgroundTintList(ContextCompat.getColorStateList(context, R.color.colorAccent));
                        break;
                    }
                    case NoAgentsAvailable: {
//                            Toast.makeText(context, "NOAGENTS  Chat", Toast.LENGTH_LONG).show();
                        isAgentAvailable = false;
                        fabChat.setBackgroundTintList(ContextCompat.getColorStateList(context, R.color.grey));
                        break;
                    }
                    case Unknown: {
//                            Toast.makeText(context, "UNKNOWN  Chat", Toast.LENGTH_LONG).show();
                        isAgentAvailable = false;
                        fabChat.setBackgroundTintList(ContextCompat.getColorStateList(context, R.color.grey));
                        break;
                    }
                }
            })
                    .onComplete(async -> {
                        Log.e("Home Fragment ", "Chat Call completed");
                        if (async.isComplete()) {
                            isAgentAvailable = true;
                            fabChat.setBackgroundTintList(ContextCompat.getColorStateList(context, R.color.colorAccent));
                        } else {
                            isAgentAvailable = false;
                            fabChat.setBackgroundTintList(ContextCompat.getColorStateList(context, R.color.grey));
                        }
//                            Toast.makeText(context, "Chat Completed!", Toast.LENGTH_LONG).show();
                    });

        } catch (Exception e) {
            Log.e(getContext().getClass().getSimpleName(), e.getMessage());
        }
Adam
  • 1,303
  • 11
  • 26

1 Answers1

0

So turns out I was missing some dependencies in my gradle files, also the updated library versions require you to use minSDK 21 where I was using minSDK 19.

Following are the dependencies needed to support chat and preChat features:

implementation 'com.salesforce.service:chat-ui:3.1.0'
implementation 'com.salesforce.service:chat-core:3.1.0'

Apparently there are no references to it in official documentation.

Reference Agent

Reference Chat

Adam
  • 1,303
  • 11
  • 26