Skip to content

Commit

Permalink
botpress
Browse files Browse the repository at this point in the history
  • Loading branch information
batorshih committed Feb 21, 2021
1 parent 4f4b4dc commit 1d78cd4
Show file tree
Hide file tree
Showing 18 changed files with 40,626 additions and 32 deletions.
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
3 changes: 3 additions & 0 deletions erxeslibrary/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.newmedia.erxeslibrary">

<uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

<uses-feature
android:name="android.hardware.camera"
android:required="true" />
Expand Down
40,152 changes: 40,151 additions & 1 deletion erxeslibrary/src/main/graphql/com.erxes.io/opens/schema.json

Large diffs are not rendered by default.

28 changes: 24 additions & 4 deletions erxeslibrary/src/main/graphql/com.erxes.io/opens/widget.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mutation widgetsMessengerConnect($brandCode: String!, $email: String, $phone: String,$isUser:Boolean, $data: JSON){
widgetsMessengerConnect (brandCode: $brandCode, email: $email, phone: $phone,isUser:$isUser, data: $data){
mutation widgetsMessengerConnect($brandCode: String!, $email: String, $phone: String,$isUser:Boolean, $data: JSON,$visitorId:String){
widgetsMessengerConnect (brandCode: $brandCode, email: $email, phone: $phone,isUser:$isUser, data: $data,visitorId:$visitorId){
integrationId
uiOptions
languageCode
Expand All @@ -17,6 +17,26 @@ mutation widgetsInsertMessage($integrationId: String!, $customerId: String!, $me
}
}

mutation widgetBotRequest(
$message: String!
$payload: String!
$type: String!
$conversationId: String
$customerId: String
$visitorId: String
$integrationId: String!
) {
widgetBotRequest(
message: $message
payload: $payload
type: $type
conversationId: $conversationId
customerId: $customerId
visitorId: $visitorId
integrationId: $integrationId
)
}

query widgetsConversations($integrationId: String!,$customerId: String!){
widgetsConversations(integrationId: $integrationId,customerId: $customerId) {
_id
Expand Down Expand Up @@ -208,8 +228,8 @@ mutation changeConversationOperator($_id: String!, $operatorStatus: String!) {
changeConversationOperator(_id: $_id, operatorStatus: $operatorStatus)
}

mutation widgetGetBotInitialMessage($integrationId: String, $customerId: String) {
widgetGetBotInitialMessage(integrationId: $integrationId, customerId: $customerId)
mutation widgetGetBotInitialMessage($integrationId: String) {
widgetGetBotInitialMessage(integrationId: $integrationId)
}

subscription ConversationMessageInserted($id: String!){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.newmedia.erxeslibrary.connection.InsertMessage;
import com.newmedia.erxeslibrary.connection.SendLead;
import com.newmedia.erxeslibrary.connection.SetConnect;
import com.newmedia.erxeslibrary.connection.WidgetBotRequest;
import com.newmedia.erxeslibrary.connection.helper.JsonCustomTypeAdapter;
import com.newmedia.erxeslibrary.connection.helper.Tls12SocketFactory;
import com.newmedia.erxeslibrary.helper.ErxesHelper;
Expand Down Expand Up @@ -202,6 +203,13 @@ public void sendLead() {
SendLead sendLead = new SendLead(this, context);
sendLead.run();
}
public void sendWidgetBotRequest(String content,String type,String payload) {
if (!config.isNetworkConnected()) {
return;
}
WidgetBotRequest widgetBotRequest = new WidgetBotRequest(this, context);
widgetBotRequest.run(content,type,payload);
}

public void changeOperator(String conversationid) {
if (!config.isNetworkConnected()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public GetBotInitialMessage(ErxesRequest erxesRequest, Context context) {

public void run() {
WidgetGetBotInitialMessageMutation mutate = WidgetGetBotInitialMessageMutation.builder()
.customerId(config.customerId)
// .customerId(config.customerId)
.integrationId(config.integrationId)
.build();
Rx3Apollo.from(erxesRequest.apolloClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public void onNext(Response<WidgetsMessagesQuery.Data> response) {
List<ConversationMessage> conversationMessages = ConversationMessage.convert(response, conversationid);
List<ConversationMessage> withoutBotList = new ArrayList<>();
for (ConversationMessage message : conversationMessages) {
if (!message.internal && message.botData == null) {
// if (!message.internal && message.botData == null) {
if (!message.internal ) {
withoutBotList.add(message);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ public void run(String mContent, List<AttachmentInput> list, String type) {
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Response<WidgetsInsertMessageMutation.Data>>() {
@Override
public void onSubscribe(Disposable d) {

}
public void onSubscribe(Disposable d) { }

@Override
public void onNext(Response<WidgetsInsertMessageMutation.Data> response) {
Expand All @@ -74,14 +72,10 @@ public void onNext(Response<WidgetsInsertMessageMutation.Data> response) {
public void onError(Throwable e) {
e.printStackTrace();
erxesRequest.notefyAll(ReturntypeUtil.CONNECTIONFAILED, null, e.getMessage(),null);

}

@Override
public void onComplete() {

}
public void onComplete() { }
});
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.newmedia.erxeslibrary.connection;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.util.Log;

import com.apollographql.apollo.api.Response;
import com.apollographql.apollo.rx3.Rx3Apollo;
Expand All @@ -14,6 +19,7 @@
import com.newmedia.erxeslibrary.utils.DataManager;

import java.util.Map;
import java.util.Random;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observer;
Expand All @@ -34,16 +40,50 @@ public SetConnect(ErxesRequest erxesRequest, Context context) {
dataManager = DataManager.getInstance(context);
}

public String getDeviceIMEI() {
try {
return Settings.Secure.getString(config.context.getContentResolver(), Settings.Secure.ANDROID_ID);
}
catch (Exception e){
return null;
}
}

public String getRandom() {
int leftLimit = 97; // letter 'a'
int rightLimit = 122; // letter 'z'
int targetStringLength = 32;
Random random = new Random();
StringBuilder buffer = new StringBuilder(targetStringLength);
for (int i = 0; i < targetStringLength; i++) {
int randomLimitedInt = leftLimit + (int)
(random.nextFloat() * (rightLimit - leftLimit + 1));
buffer.append((char) randomLimitedInt);
}
String generatedString = buffer.toString();
return generatedString;
}
public void run(boolean isCheckRequired, boolean isUser, boolean hasData, String email, String phone, String data) {
this.customData = data;
Gson gson = new Gson();
Map customDataMap = gson.fromJson(data, Map.class);
String imei = getDeviceIMEI();

if(imei == null){
if(dataManager.getDataS(DataManager.ANDROID_UNIQUE)==null){
imei = getRandom();
dataManager.setData(DataManager.ANDROID_UNIQUE,imei);
} else {
imei = dataManager.getDataS(DataManager.ANDROID_UNIQUE);
}
}

WidgetsMessengerConnectMutation mutate = WidgetsMessengerConnectMutation.builder()
.brandCode(config.brandCode)
.email(email)
.phone(phone)
.isUser(isUser)
.visitorId(imei)
.data(new Json(customDataMap))
.build();
Rx3Apollo.from(erxesRequest.apolloClient
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.newmedia.erxeslibrary.connection;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import com.apollographql.apollo.api.Response;
import com.apollographql.apollo.rx3.Rx3Apollo;
import com.erxes.io.opens.WidgetBotRequestMutation;
import com.erxes.io.opens.WidgetsInsertMessageMutation;
import com.erxes.io.opens.type.AttachmentInput;
import com.newmedia.erxeslibrary.configuration.Config;
import com.newmedia.erxeslibrary.configuration.ErxesRequest;
import com.newmedia.erxeslibrary.model.ConversationMessage;
import com.newmedia.erxeslibrary.utils.ReturntypeUtil;

import java.util.List;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.schedulers.Schedulers;

public class WidgetBotRequest {
final static String TAG = "widgetBotRequest";
private final ErxesRequest erxesRequest;
private final Config config;
private final Context context;

public WidgetBotRequest(ErxesRequest erxesRequest, Context context) {
this.erxesRequest = erxesRequest;
this.context = context;
config = Config.getInstance(context);
}

public void run(String mContent, String type,String payload) {
if (TextUtils.isEmpty(mContent) ) {
mContent = "This message has an attachment";
}
WidgetBotRequestMutation.Builder temp = WidgetBotRequestMutation.builder()
.integrationId(config.integrationId)
.customerId(config.customerId)
.message(mContent)
.conversationId(config.conversationId)
.payload(payload)
.type(type);

String finalMContent = mContent;
Rx3Apollo.from(erxesRequest.apolloClient
.mutate(temp.build()))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Response<WidgetBotRequestMutation.Data>>() {
@Override
public void onSubscribe(Disposable d) {

}

@Override
public void onNext(Response<WidgetBotRequestMutation.Data> response) {
if (response.hasErrors()) {
erxesRequest.notefyAll(ReturntypeUtil.SERVERERROR, config.conversationId, response.getErrors().get(0).getMessage(),null);
} else {
if (response.getData() != null) {
Log.d("fuck"," xx "+response.getData().widgetBotRequest().toString());
erxesRequest.notefyAll(ReturntypeUtil.GETBOTINITIALMESSAGE, config.conversationId, null, response.getData().widgetBotRequest());
}
}
}

@Override
public void onError(Throwable e) {
e.printStackTrace();
erxesRequest.notefyAll(ReturntypeUtil.CONNECTIONFAILED, null, e.getMessage(),null);

}

@Override
public void onComplete() {

}
});
}

}
Loading

0 comments on commit 1d78cd4

Please sign in to comment.