Exemplo n.º 1
0
  public Message sendMessage(
      TelegramChat chat,
      String text,
      Boolean disableWebPagePreview,
      Message replyToMessage,
      ReplyMarkup markup)
      throws JSONException, UnsupportedOperationException, IOException, URISyntaxException {
    if (chat == null) {
      throw new NullPointerException("The chat argument must not be null.");
    }
    if (text == null) {
      throw new NullPointerException("The text argument must not be null.");
    }
    JSONObject data = new JSONObject();
    data.put("chat_id", chat.getId());
    data.put("text", text);
    if (disableWebPagePreview != null) {
      data.put("disable_web_page_preview", disableWebPagePreview);
    }
    if (replyToMessage != null) {
      data.put("reply_to_message_id", replyToMessage.getMessageId());
    }
    if (markup != null) {
      data.put("reply_markup", markup.toJSONObject());
    }

    JSONObject response =
        new Request(getURIFromMethod("sendMessage")).execute(data).getResultAsJSONObject();
    if (response.getBoolean("ok")) {
      return new Message(response.getJSONObject("result"));
    } else {
      throw new TelegramAPIError(response.getString("description"));
    }
  }
Exemplo n.º 2
0
  public Message sendLocation(
      TelegramChat chat,
      float latitude,
      float longitude,
      Message replyToMessage,
      ReplyMarkup markup)
      throws JSONException, UnsupportedOperationException, IOException, URISyntaxException {
    if (chat == null) {
      throw new NullPointerException("The chat argument must not be null.");
    }
    JSONObject data = new JSONObject();
    data.put("chat_id", chat.getId());
    data.put("latutide", latitude);
    data.put("longitude", longitude);
    if (replyToMessage != null) {
      data.put("reply_to_message_id", replyToMessage.getMessageId());
    }
    if (markup != null) {
      data.put("reply_markup", markup.toJSONObject());
    }

    JSONObject response =
        new Request(getURIFromMethod("sendLocation")).execute(data).getResultAsJSONObject();
    if (response.getBoolean("ok")) {
      return new Message(response.getJSONObject("result"));
    } else {
      throw new TelegramAPIError(response.getString("description"));
    }
  }