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

[android] Option are wrong evaluated #24 #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import com.zendesk.logger.Logger;

import java.lang.String;
import java.util.ArrayList;
import java.util.List;

import zendesk.chat.Chat;
import zendesk.chat.ChatConfiguration;
import zendesk.chat.ChatEngine;
Expand All @@ -22,17 +25,20 @@
import zendesk.chat.PushNotificationsProvider;
import zendesk.chat.Providers;
import zendesk.chat.VisitorInfo;
import zendesk.configurations.Configuration;
import zendesk.core.JwtIdentity;
import zendesk.core.AnonymousIdentity;
import zendesk.core.Identity;
import zendesk.messaging.MessagingActivity;
import zendesk.core.Zendesk;
import zendesk.support.CustomField;
import zendesk.support.Support;
import zendesk.support.guide.HelpCenterActivity;
import zendesk.support.guide.ViewArticleActivity;
import zendesk.answerbot.AnswerBot;
import zendesk.answerbot.AnswerBotEngine;
import zendesk.support.SupportEngine;
import zendesk.support.request.RequestActivity;

public class RNZendeskChat extends ReactContextBaseJavaModule {

Expand All @@ -49,13 +55,22 @@ public String getName() {
return "RNZendeskChat";
}

private String getBotName(ReadableMap options){
if(options.hasKey("botName")){
return options.getString("botName");
/* helper methods */
private Boolean getBoolean(ReadableMap options, String key){
if(options.hasKey(key)){
return options.getBoolean(key);
}
return "Chat Bot";
return null;
}

private String getString(ReadableMap options, String key){
if(options.hasKey(key)){
return options.getString(key);
}
return null;
}


@ReactMethod
public void setVisitorInfo(ReadableMap options) {

Expand All @@ -75,19 +90,23 @@ public void setVisitorInfo(ReadableMap options) {
return;
}
VisitorInfo.Builder builder = VisitorInfo.builder();
if (options.hasKey("name")) {
builder = builder.withName(options.getString("name"));
String name = getString(options,"name");
String email = getString(options,"email");
String phone = getString(options,"phone");
String department = getString(options,"department");
if (name != null) {
builder = builder.withName(name);
}
if (options.hasKey("email")) {
builder = builder.withEmail(options.getString("email"));
if (email != null) {
builder = builder.withEmail(email);
}
if (options.hasKey("phone")) {
builder = builder.withPhoneNumber(options.getString("phone"));
if (phone != null) {
builder = builder.withPhoneNumber(phone);
}
VisitorInfo visitorInfo = builder.build();
profileProvider.setVisitorInfo(visitorInfo, null);
if (options.hasKey("department"))
chatProvider.setDepartment(options.getString("department"), null);
if (department != null)
chatProvider.setDepartment(department, null);

}

Expand Down Expand Up @@ -123,8 +142,9 @@ public void initChat(String key) {

@ReactMethod
public void setUserIdentity(ReadableMap options) {
if (options.hasKey("token")) {
Identity identity = new JwtIdentity(options.getString("token"));
String token = getString(options,"token");
if (token != null) {
Identity identity = new JwtIdentity(token);
Zendesk.INSTANCE.setIdentity(identity);
} else {
String name = options.getString("name");
Expand All @@ -139,11 +159,22 @@ public void setUserIdentity(ReadableMap options) {
@ReactMethod
public void showHelpCenter(ReadableMap options) {
Activity activity = getCurrentActivity();
if (options.hasKey("withChat")) {
/*
// config must be passed as 2nd parameter to show method
List<CustomField> customFields = new ArrayList<>();
customFields.add(new CustomField(360028434358L, "testValoreDaApp"));
Configuration config = RequestActivity.builder()
.withCustomFields(customFields)
.withTags("tag1","tag2")
.config();
*/
Boolean withChat = getBoolean(options,"withChat");
Boolean disableTicketCreation = getBoolean(options,"withChat");
if (withChat) {
HelpCenterActivity.builder()
.withEngines(ChatEngine.engine())
.show(activity);
} else if (options.hasKey("disableTicketCreation")) {
} else if (disableTicketCreation) {
HelpCenterActivity.builder()
.withContactUsButtonVisible(false)
.withShowConversationsMenuButton(false)
Expand All @@ -161,7 +192,8 @@ public void startChat(ReadableMap options) {
setUserIdentity(options);
setVisitorInfo(options);
setUserIdentity(options);
String botName = getBotName(options);
String botName = getString(options,"botName");
botName = botName == null ? "bot name" : botName;
ChatConfiguration chatConfiguration = ChatConfiguration.builder()
.withAgentAvailabilityEnabled(true)
.withOfflineFormEnabled(true)
Expand Down