1 package com.netease.nimlib.sdk.robot.model;
6 import org.json.JSONException;
7 import org.json.JSONObject;
16 private static final String TAG_ROBOT_SEND =
"msgOut";
17 private static final String TAG_ROBOT_ACCID =
"robotAccid";
20 private static final String TAG_CLIENT_MSG_ID =
"clientMsgId";
21 private static final String TAG_ROBOT_MSG =
"robotMsg";
24 private static final String TAG_PARAM =
"param";
25 private static final String TAG_REQUEST_TYPE =
"type";
26 private static final String TAG_REQUEST_CONTENT =
"content";
27 private static final String TAG_REQUEST_TARGET =
"target";
28 private static final String TAG_REQUEST_PARAMS =
"params";
31 private String fromRobotAccount;
33 private String responseForMessageId;
34 private String response;
36 private String requestType;
37 private String requestContent;
38 private String requestTarget;
39 private String requestParams;
49 public void initSend(String robotAccount, String type, String content, String target, String params) {
50 this.fromRobotAccount = robotAccount;
51 this.requestType = type;
52 this.requestContent = content;
53 this.requestTarget = target;
54 this.requestParams = params;
55 this.isRobotSend =
false;
58 private void fromJson(String attach) {
59 JSONObject json = JSONHelper.parse(attach);
60 isRobotSend = JSONHelper.getBoolean(json, TAG_ROBOT_SEND);
61 fromRobotAccount = JSONHelper.getString(json, TAG_ROBOT_ACCID);
62 responseForMessageId = JSONHelper.getString(json, TAG_CLIENT_MSG_ID);
63 JSONObject responseObject = JSONHelper.getJSONObject(json, TAG_ROBOT_MSG);
64 if (responseObject != null) {
65 response = responseObject.toString();
67 JSONObject paramJson = JSONHelper.getJSONObject(json, TAG_PARAM);
68 if (paramJson != null) {
69 requestType = JSONHelper.getString(paramJson, TAG_REQUEST_TYPE);
70 requestContent = JSONHelper.getString(paramJson, TAG_REQUEST_CONTENT);
71 requestTarget = JSONHelper.getString(paramJson, TAG_REQUEST_TARGET);
72 requestParams = JSONHelper.getString(paramJson, TAG_REQUEST_PARAMS);
78 JSONObject jsonObject =
new JSONObject();
82 JSONObject paramObject =
new JSONObject();
83 paramObject.put(TAG_REQUEST_TYPE, requestType);
84 paramObject.put(TAG_REQUEST_CONTENT, requestContent);
85 paramObject.put(TAG_REQUEST_TARGET, requestTarget);
86 paramObject.put(TAG_REQUEST_PARAMS, requestParams);
87 jsonObject.put(TAG_PARAM, paramObject);
90 jsonObject.put(TAG_ROBOT_MSG, response);
91 jsonObject.put(TAG_CLIENT_MSG_ID, responseForMessageId);
94 jsonObject.put(TAG_ROBOT_ACCID, fromRobotAccount);
95 jsonObject.put(TAG_ROBOT_SEND, isRobotSend);
96 }
catch (JSONException e) {
100 return jsonObject.toString();
108 this.isRobotSend = robotSend;
112 return fromRobotAccount;
116 this.fromRobotAccount = fromRobotAccount;
120 return responseForMessageId;
124 this.responseForMessageId = responseForMessageId;
136 this.requestType = requestType;
140 return requestContent;
144 this.requestContent = requestContent;
148 return requestTarget;
152 this.requestTarget = requestTarget;
156 return requestParams;
160 this.requestParams = requestParams;
void setResponseForMessageId(String responseForMessageId)
RobotAttachment(String attStr)
String getRequestContent()
void setRobotSend(boolean robotSend)
void setRequestType(String requestType)
void setFromRobotAccount(String fromRobotAccount)
void setRequestContent(String requestContent)
void initSend(String robotAccount, String type, String content, String target, String params)
String getRequestTarget()
String toJson(boolean send)
将消息附件序列化为字符串,存储到消息数据库或发送到服务器。
String getFromRobotAccount()
String getResponseForMessageId()
void setRequestTarget(String requestTarget)
String getRequestParams()
void setRequestParams(String requestParams)