Add whatsapp call messages

This commit is contained in:
2022-10-17 11:17:12 +01:00
parent 87e01db551
commit 34cc097d45
2 changed files with 58 additions and 0 deletions

View File

@@ -17,25 +17,49 @@
*/ */
package com.axelor.apps.base.web; package com.axelor.apps.base.web;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.List;
import org.apache.batik.util.io.StringDecoder;
import com.axelor.app.AppSettings; import com.axelor.app.AppSettings;
import com.axelor.apps.base.db.AppBase; import com.axelor.apps.base.db.AppBase;
import com.axelor.apps.base.exceptions.IExceptionMessage; import com.axelor.apps.base.exceptions.IExceptionMessage;
import com.axelor.apps.base.service.CurrencyConversionService; import com.axelor.apps.base.service.CurrencyConversionService;
import com.axelor.apps.base.service.MapService; import com.axelor.apps.base.service.MapService;
import com.axelor.apps.base.service.administration.ExportDbObjectService; import com.axelor.apps.base.service.administration.ExportDbObjectService;
import com.axelor.apps.base.service.app.AppBaseService;
import com.axelor.exception.AxelorException; import com.axelor.exception.AxelorException;
import com.axelor.exception.service.TraceBackService; import com.axelor.exception.service.TraceBackService;
import com.axelor.i18n.I18n; import com.axelor.i18n.I18n;
import com.axelor.inject.Beans; import com.axelor.inject.Beans;
import com.axelor.meta.CallMethod;
import com.axelor.meta.db.MetaFile; import com.axelor.meta.db.MetaFile;
import com.axelor.meta.schema.actions.ActionView; import com.axelor.meta.schema.actions.ActionView;
import com.axelor.rpc.ActionRequest; import com.axelor.rpc.ActionRequest;
import com.axelor.rpc.ActionResponse; import com.axelor.rpc.ActionResponse;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import com.mongodb.util.JSON;
import net.minidev.json.JSONObject;
@Singleton @Singleton
public class AppBaseController { public class AppBaseController {
/**
*
*/
private static final String localhost = "127.0.0.1";
public void exportObjects(ActionRequest request, ActionResponse response) { public void exportObjects(ActionRequest request, ActionResponse response) {
MetaFile metaFile = Beans.get(ExportDbObjectService.class).exportObject(); MetaFile metaFile = Beans.get(ExportDbObjectService.class).exportObject();
if (metaFile == null) { if (metaFile == null) {
@@ -111,4 +135,35 @@ public class AppBaseController {
TraceBackService.trace(e); TraceBackService.trace(e);
} }
} }
@CallMethod
public void execWhatsApp(String username,String message,String url,String id,String enc) throws IOException, ClassNotFoundException {
try{
String uri = Beans.get(AppBaseService.class).getAppBase().getWhatsAppURL();
String fullUrl = uri + "/"+ url + "/" + id;
Socket socket = new Socket(localhost, 6060);
// String data = "{\"username\" : \"" + username + "\",\"url\": \""+ fullUrl +"\",\"message\":\""+ message +"\"}";
String data = username + "***"+ fullUrl +"***"+ message;
DataOutputStream dout=new DataOutputStream(socket.getOutputStream());
DataInputStream in = new DataInputStream(socket.getInputStream());
dout.writeUTF(data);
String msg=(String)in.readUTF();
if( msg == "message_received"){
dout.flush();
dout.close();
// socket.close();
System.out.println("Message: " + msg);
}
}
catch(Exception e) {
e.printStackTrace();
}
}
} }

View File

@@ -26,6 +26,9 @@
<!-- Currency Conversion Webservice URL --> <!-- Currency Conversion Webservice URL -->
<string name="currencyWsURL" title="Currency Ws URL" selection="base.app.base.currency.api.select"/> <string name="currencyWsURL" title="Currency Ws URL" selection="base.app.base.currency.api.select"/>
<!-- whatsapp url -->
<string name="whatsAppURL" title="WhatsApp URL" />
<one-to-many name="currencyConversionLineList" ref="com.axelor.apps.base.db.CurrencyConversionLine" mappedBy="appBase" title="Currency conversion table"/> <one-to-many name="currencyConversionLineList" ref="com.axelor.apps.base.db.CurrencyConversionLine" mappedBy="appBase" title="Currency conversion table"/>
<boolean name="hasQasValidation" title="Use QAS Validation"/> <boolean name="hasQasValidation" title="Use QAS Validation"/>