|
| 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 | +} |
0 commit comments