Skip to content

Commit

Permalink
Merge pull request #443 from Kommunicate-io/CM-1666
Browse files Browse the repository at this point in the history
[CM-1666] - FIxed submit button
  • Loading branch information
pranaysaini04 authored Nov 2, 2023
2 parents 1919fa1 + 817c897 commit b514a16
Showing 1 changed file with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
Expand Down Expand Up @@ -225,7 +227,37 @@ public void handleSubmitButton(Context context, Object object) {
}
} else if (object instanceof KmRichMessageModel) {
KmRichMessageModel model = (KmRichMessageModel) object;
openWebLink(model.getFormData(), model.getFormAction());
try {
Map<String, String> localeMetadata = new HashMap<>();
localeMetadata.put(null,null);
String payloadString = model.getPayload();
JSONArray payloadArray = new JSONArray(payloadString);
JSONObject jsonObject = payloadArray.getJSONObject(0);
String replyText = jsonObject.getString("replyText");
sendMessage(replyText,localeMetadata, Message.ContentType.DEFAULT.getValue());
if (!model.getFormAction().isEmpty()) {
new KmPostDataAsyncTask(context,
model.getFormAction(),
null,
((KmRichMessageModel) object).getRequestType(),
model.getFormData(),
new KmCallback() {
@Override
public void onSuccess(Object messageString) {
Utils.printLog(context, TAG, "Submit post success : " + messageString);
}

@Override
public void onFailure(Object error) {
Utils.printLog(context, TAG, "Submit post error : " + error);
}
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

} catch (JSONException e) {
e.printStackTrace();
}

} else if (object instanceof KmRichMessageModel.KmPayloadModel) {
makeFormRequest(context, (KmRichMessageModel.KmPayloadModel) object);
}
Expand Down

0 comments on commit b514a16

Please sign in to comment.