JSONObject interactiveData = new JSONObject();
try {
interactiveData.put("title", "Demo Form");
JSONArray jsonArray = new JSONArray();
JSONObject textInput = new JSONObject();
textInput.put("elementType", "textInput");
textInput.put("elementId", "element1");
textInput.put("label", "Name");
textInput.put("optional", false);
textInput.put("maxLines", 1);
jsonArray.put(textInput);
interactiveData.put("formFields", jsonArray);
JSONObject submitElement = new JSONObject();
submitElement.put("elementType", "button");
submitElement.put("elementId", "element8");
submitElement.put("buttonText", "Submit");
submitElement.put("disableAfterInteracted", true);
JSONObject action = new JSONObject();
action.put("actionType", "urlNavigation");
action.put("url", "https://www.cometchat.com/");
submitElement.put("action", action);
interactiveData.put("submitElement", submitElement);
} catch (JSONException e) {
throw new RuntimeException(e);
}
InteractiveMessage interactiveMessage = new InteractiveMessage(receiverId,receiverType,"form", interactiveData);
CometChat.sendInteractiveMessage(interactiveMessage, new CometChat.CallbackListener<InteractiveMessage>() {
@Override
public void onSuccess(InteractiveMessage interactiveMessage) {
// This block is executed when the InteractiveMessage is sent successfully.
}
@Override
public void onError(CometChatException e) {
// This block is executed if an error occurs while sending the InteractiveMessage.
}
});