Exemplo n.º 1
0
  public Message sendSticker(
      TelegramChat chat, Sticker file, String caption, Message replyToMessage, ReplyMarkup markup)
      throws JSONException, UnsupportedOperationException, IOException, URISyntaxException {
    if (chat == null) {
      throw new NullPointerException("The chat argument must not be null.");
    }
    if (file == null) {
      throw new NullPointerException("The file argument must not be null.");
    }
    JSONObject data = new JSONObject();
    data.put("chat_id", chat.getId());
    data.put("sticker", file.getFileId());
    if (caption != null) {
      data.put("caption", caption);
    }
    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("sendSticker")).execute(data).getResultAsJSONObject();
    if (response.getBoolean("ok")) {
      return new Message(response.getJSONObject("result"));
    } else {
      throw new TelegramAPIError(response.getString("description"));
    }
  }