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

Sync with fork #1

Merged
merged 2 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
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
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