Skip to content

Commit

Permalink
Merge pull request #1 from pagopa/sync-with-fork
Browse files Browse the repository at this point in the history
Sync with fork
  • Loading branch information
debiff authored Nov 2, 2021
2 parents f880c84 + 8d551f8 commit 2ca3181
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 21 deletions.
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
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "react-native-zendesk-v2",
"version": "0.2.1",
"version": "0.3.4",
"description": "React native wrapper for Zendesk Unified SDK",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/Saranshmalik/react-native-zendesk.git"
"url": "https://github.com/pagopa/io-react-native-zendesk"
},
"keywords": [
"react-native",
Expand All @@ -19,8 +19,8 @@
"chat",
"zendesk unified sdkv2"
],
"homepage": "https://github.com/Saranshmalik/react-native-zendesk.git",
"author": "Saranshmalik",
"homepage": "https://github.com/pagopa/io-react-native-zendesk.git",
"author": "forked by PagoPA S.p.A - original author @Saranshmalik",
"license": "MIT",
"peerDependencies": {
"react": "~16.11.0",
Expand Down

0 comments on commit 2ca3181

Please sign in to comment.