支援在 React Native 應用程式中顯示 Zendesk Chat 的簡單模組。
該程式庫假設您熟悉 Zendesk 的官方文件:iOS 和 Android。
使用 npm:
npm install react-native-zendesk-chat --save
或用紗線:
yarn add react-native-zendesk-chat
$ yarn install # and see if there are any errors
$ (cd ios ; pod install) # and see if there are any errors
# -- you may need to do `pod install --repo-update`
如果您使用的是較舊的反應本機版本,請參閱下方的進階設定部分
Android如果您使用的是 React-native >= 0.60,Android 應該會自動偵測此依賴項。如果你使用的是0.59,你可能需要呼叫react-native link
import ZendeskChat from "react-native-zendesk-chat" ;
// Once in your application:
ZendeskChat . init ( "YOUR_ZENDESK_ACCOUNT_KEY" ) ;
// Optionally specify the appId provided by Zendesk
ZendeskChat . init ( "YOUR_ZENDESK_ACCOUNT_KEY" , "APP_ID_PROVIDED_BY_ZENDESK" ) ;
// On button press, when you want to show chat:
ZendeskChat . startChat ( {
name : user . full_name ,
email : user . email ,
phone : user . mobile_phone ,
tags : [ "tag1" , "tag2" ] ,
department : "Your department" ,
// The behaviorFlags are optional, and each default to 'true' if omitted
behaviorFlags : {
showAgentAvailability : true ,
showChatTranscriptPrompt : true ,
showPreChatForm : true ,
showOfflineForm : true ,
} ,
// The preChatFormOptions are optional & each defaults to "optional" if omitted
preChatFormOptions : {
name : ! user . full_name ? "required" : "optional" ,
email : "optional" ,
phone : "optional" ,
department : "required" ,
} ,
localizedDismissButtonTitle : "Dismiss" ,
} ) ;
YOUR_ZENDESK_ACCOUNT_KEY
若要取得您的 zendesk 帳號金鑰,請參閱 Zendesk SDK 中初始化 SDK 中的說明。
若要取得您的帳戶金鑰,請依照下列步驟操作:
更改 UI 樣式主要是透過本機技術實現的。
在 Android 上,這是官方文件 - 一個範例可能是將這 3 行添加到您的應用程式主題中
在 iOS 上,選項更少——查看官方文件頁面
來自react-native-zendesk-chat <= 0.3.0
要從先前版本的庫遷移,您可能應該刪除應用程式的所有整合步驟,並從快速入門重新開始。
JS API 呼叫非常相似,主要是附加變更。
高級用戶或在舊版本的react-native上運行的用戶可能希望在本機中初始化事物。
如果您使用的 iOS < 0.60,您可能需要手動安裝 cocoapod:
新增對您的 Podfile 的引用:
pod 'RNZendeskChat', :git => 'https://github.com/taskrabbit/react-native-zendesk-chat.git'
然後運行 pod install: (cd ios; pod install)
或手動:
在 Xcode 中,將node_modules/react-native-zendesk-chat/RNZendeskChat.m
和node_modules/react-native-zendesk-chat/RNZendeskChat.h
拖曳到您的專案中。
AppDelegate.m
中設定ZDCChat
: # import < ZDCChat/ZDCChat.h >
// ...
// Inside the appropriate appDidFinishLaunching method
[ZDCChat initializeWithAccountKey: @" YOUR_ZENDESK_ACCOUNT_KEY " appId: " YOUR_ZENDESK_APP_ID " ];
// And access other interesting APIs
如果您的react-native < 0.60,您應該能夠呼叫react-native link
。
如果這不起作用,那麼您可能需要執行完整的手動安裝,如下所示:
android/app/main/java/[...]/MainApplication.java
import com.taskrabbit.zendesk.*;
到文件頂部的導入new RNZendeskChatPackage(this)
加入getPackages()
方法傳回的清單中android/settings.gradle
: include ' :react-native-zendesk-chat '
project( ' :react-native-zendesk-chat ' ) . projectDir = new File (rootProject . projectDir, ' ../node_modules/react-native-zendesk-chat/android ' )
android/app/build.gradle
的依賴項區塊中插入以下行:對於 RN >= 0.60:
dependencies {
//
api group : ' com.zendesk ' , name : ' chat ' , version : ' 2.2.0 '
api group : ' com.zendesk ' , name : ' messaging ' , version : ' 4.3.1 '
也在項目 build.gradle 中
新增gradle maven { url 'https://zendesk.jfrog.io/zendesk/repo' }
對於 RN < 0.60:
compile project( ' :react-native-zendesk-chat ' )
android/app/main/java/[...]/MainActivity.java
中設定Chat
// Note: there is a JS method to do this -- prefer doing that! -- This is for advanced users only.
// Call this once in your Activity's bootup lifecycle
Chat . INSTANCE . init ( mReactContext , key , appId );
main
react native zendesk chat已獲得 MIT 許可,如 LICENSE 文件所示。