Skip to content

Commit 328ef89

Browse files
committed
Initial Commit
0 parents  commit 328ef89

File tree

11 files changed

+555
-0
lines changed

11 files changed

+555
-0
lines changed

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Dependency directory
2+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
3+
node_modules
4+
ios/RNZendeskChat/RNZendeskChat.xcodeproj/xcuserdata
5+
ios/RNZendeskChat/RNZendeskChat.xcodeproj/project.xcworkspace
6+
7+
# Android/IJ
8+
#
9+
.idea
10+
.gradle
11+
**/*.iml
12+
local.properties
13+
14+
# Xcode
15+
#
16+
build/
17+
*.pbxuser
18+
!default.pbxuser
19+
*.mode1v3
20+
!default.mode1v3
21+
*.mode2v3
22+
!default.mode2v3
23+
*.perspectivev3
24+
!default.perspectivev3
25+
*.xcworkspace
26+
!Scripts/xctool/xctool.xcworkspace
27+
!default.xcworkspace
28+
xcuserdata
29+
*.xccheckout
30+
*.moved-aside
31+
DerivedData
32+
*.hmap
33+
*.ipa
34+
*.xcuserstate
35+
project.xcworkspace

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# react-native-zendesk-chat
2+
3+
Simple module that allows displaying Zopim Chat from Zendesk for React Native.
4+
5+
## Known issues
6+
7+
I could not find how to make the import for iOS work properly since I'm using Cocoapods for Zendesk, if you have a suggestion that would be great.
8+
9+
## Getting started
10+
11+
Follow the instructions to install the SDK for [iOS](https://developer.zendesk.com/embeddables/docs/ios-chat-sdk/gettingstarted) and [Android](https://developer.zendesk.com/embeddables/docs/android/gettingstarted).
12+
13+
### Manual install
14+
#### iOS
15+
1. `npm install react-native-zendesk-chat --save`
16+
2. In Xcode, drag and drop `node_modules/react-native-zendesk-chat/RNZendeskChat.m` and `node_modules/react-native-zendesk-chat/RNZendeskChat.h` into your project.
17+
3. Configure `ZDCChat` in `AppDelegate.m`:
18+
19+
```
20+
[ZDCChat configure:^(ZDCConfig *defaults) {
21+
defaults.accountKey = "YOUR_ZENDESK_ACCOUNT_KEY";
22+
}];
23+
```
24+
25+
#### Android
26+
1. `npm install react-native-zendesk-chat --save`
27+
2. Open up `android/app/main/java/[...]/MainActivity.java`
28+
- Add `import com.taskrabbit.zendesk.*;` to the imports at the top of the file
29+
- Add `new RNZendeskChatPackage(this)` to the list returned by the `getPackages()` method
30+
31+
3. Append the following lines to `android/settings.gradle`:
32+
33+
```
34+
include ':react-native-zendesk-chat'
35+
project(':react-native-zendesk-chat').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-zendesk-chat/android')
36+
```
37+
38+
4. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
39+
40+
```
41+
compile project(':react-native-zendesk-chat')
42+
```
43+
44+
5. Configure `ZopimChat` in `android/app/main/java/[...]/MainActivity.java`
45+
46+
```
47+
ZopimChat.init("YOUR_ZENDESK_ACCOUNT_KEY").build();
48+
```
49+
50+
## Usage
51+
52+
In your code add `import ZendeskChat from 'react-native-zendesk-chat';`.
53+
54+
```
55+
ZendeskChat.startChat({
56+
name: user.full_name,
57+
email: user.email,
58+
phone: user.mobile_phone,
59+
});
60+
```
61+
62+
## TODO
63+
64+
* Allow setting form configuration from JS
65+
* Add examples

android/build.gradle

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
}
5+
6+
dependencies {
7+
classpath 'com.android.tools.build:gradle:1.2.3'
8+
}
9+
}
10+
11+
apply plugin: 'com.android.library'
12+
13+
android {
14+
compileSdkVersion 23
15+
buildToolsVersion "23.0.1"
16+
17+
defaultConfig {
18+
minSdkVersion 16
19+
targetSdkVersion 22
20+
versionCode 1
21+
versionName "1.0"
22+
}
23+
}
24+
25+
repositories {
26+
mavenCentral()
27+
maven { url 'https://zendesk.artifactoryonline.com/zendesk/repo' }
28+
}
29+
30+
dependencies {
31+
compile 'com.facebook.react:react-native:0.17.+'
32+
compile group: 'com.zopim.android', name: 'sdk', version: '1.1.1'
33+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.taskrabbit.zendesk.RNZendeskChat" >
3+
</manifest>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.taskrabbit.zendesk;
2+
3+
import android.app.Activity;
4+
import android.content.Intent;
5+
import com.facebook.react.bridge.*;
6+
import com.zopim.android.sdk.api.ZopimChat;
7+
import com.zopim.android.sdk.model.VisitorInfo;
8+
import com.zopim.android.sdk.prechat.ZopimChatActivity;
9+
10+
public class RNZendeskChatModule extends ReactContextBaseJavaModule {
11+
private ReactContext mReactContext;
12+
private Activity mActivity;
13+
14+
public RNZendeskChatModule(ReactApplicationContext reactContext, Activity activity) {
15+
super(reactContext);
16+
17+
mActivity = activity;
18+
mReactContext = reactContext;
19+
}
20+
21+
@Override
22+
public String getName() {
23+
return "RNZendeskChatModule";
24+
}
25+
26+
@ReactMethod
27+
public void setVisitorInfo(ReadableMap options) {
28+
VisitorInfo.Builder builder = new VisitorInfo.Builder();
29+
30+
if (options.hasKey("name")) {
31+
builder.name(options.getString("name"));
32+
}
33+
if (options.hasKey("email")) {
34+
builder.email(options.getString("email"));
35+
}
36+
if (options.hasKey("phone")) {
37+
builder.phoneNumber(options.getString("phone"));
38+
}
39+
40+
VisitorInfo visitorData = builder.build();
41+
42+
ZopimChat.setVisitorInfo(visitorData);
43+
}
44+
45+
@ReactMethod
46+
public void startChat(ReadableMap options) {
47+
setVisitorInfo(options);
48+
mActivity.startActivity(new Intent(mReactContext, ZopimChatActivity.class));
49+
}
50+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.taskrabbit.zendesk;
2+
3+
import android.app.Activity;
4+
5+
import com.facebook.react.ReactPackage;
6+
import com.facebook.react.bridge.JavaScriptModule;
7+
import com.facebook.react.bridge.NativeModule;
8+
import com.facebook.react.bridge.ReactApplicationContext;
9+
import com.facebook.react.uimanager.ViewManager;
10+
11+
import java.util.ArrayList;
12+
import java.util.Collections;
13+
import java.util.List;
14+
15+
public class RNZendeskChatPackage implements ReactPackage {
16+
Activity mActivity;
17+
18+
public RNZendeskChatPackage(Activity activity) {
19+
mActivity = activity;
20+
}
21+
22+
@Override
23+
public List<NativeModule> createNativeModules(
24+
ReactApplicationContext reactContext) {
25+
List<NativeModule> modules = new ArrayList<>();
26+
27+
modules.add(new RNZendeskChatModule(reactContext, mActivity));
28+
return modules;
29+
}
30+
31+
@Override
32+
public List<Class<? extends JavaScriptModule>> createJSModules() {
33+
return Collections.emptyList();
34+
}
35+
36+
@Override
37+
public List<ViewManager> createViewManagers(ReactApplicationContext reactApplicationContext) {
38+
return Collections.emptyList();
39+
}
40+
41+
}

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { NativeModules } from 'react-native';
2+
3+
const RNZendeskChatModule = NativeModules.RNZendeskChatModule;
4+
5+
export default RNZendeskChatModule;

0 commit comments

Comments
 (0)