use of com.github.jamesnetherton.zulip.client.api.message.response.SendMessageApiResponse in project zulip-java-client by jamesnetherton.
the class SendMessageApiRequest method execute.
/**
* Executes the Zulip API request for sending a message.
*
* @return The id of the message
* @throws ZulipClientException if the request was not successful
*/
@Override
public Long execute() throws ZulipClientException {
final Map<String, Object> params = getParams();
final Map<String, Object> modified = new HashMap<>();
if (params.get(TYPE) != null) {
for (Map.Entry<String, Object> entry : params.entrySet()) {
if (!entry.getKey().equals(TO_PRIVATE) && !entry.getKey().equals(TO_STREAM)) {
modified.put(entry.getKey(), entry.getValue());
}
}
String type = (String) params.get(TYPE);
if (type.equals(MessageType.PRIVATE.toString())) {
try {
modified.put(TO, JsonUtils.getMapper().writeValueAsString(params.get(TO_PRIVATE)));
} catch (JsonProcessingException e) {
throw new ZulipClientException(e);
}
} else {
modified.put(TO, params.get(TO_STREAM));
}
}
SendMessageApiResponse response = client().post(MESSAGES_API_PATH, modified, SendMessageApiResponse.class);
return response.getId();
}
Aggregations