public JSONMessage text(String text) {
   MessagePart latest = latest();
   if (latest.hasText()) {
     throw new IllegalStateException("text for this message part is already set");
   }
   latest.text = text;
   dirty = true;
   return this;
 }
 public String toJSONString() {
   if (!dirty && jsonString != null) {
     return jsonString;
   }
   StringWriter string = new StringWriter();
   JsonWriter json = new JsonWriter(string);
   try {
     if (messageParts.size() == 1) {
       latest().writeJson(json);
     } else {
       json.beginObject().name("text").value("").name("extra").beginArray();
       for (final MessagePart part : messageParts) {
         part.writeJson(json);
       }
       json.endArray().endObject();
       json.close();
     }
   } catch (Exception e) {
     throw new RuntimeException("invalid message");
   }
   jsonString = string.toString();
   dirty = false;
   return jsonString;
 }
 private void onHover(final String name, final String data) {
   final MessagePart latest = latest();
   latest.hoverActionName = name;
   latest.hoverActionData = data;
   dirty = true;
 }
 private void onClick(final String name, final String data) {
   final MessagePart latest = latest();
   latest.clickActionName = name;
   latest.clickActionData = data;
   dirty = true;
 }