message builder, sending Documents
This commit is contained in:
parent
69cb78ce5c
commit
6d6a17a4df
|
@ -169,8 +169,14 @@ public class MessageBuilder {
|
|||
throw new MissingException("Text");
|
||||
}
|
||||
}
|
||||
if(no_web_view) {
|
||||
optionals += "&disable_web_page_preview=" + no_web_view;
|
||||
}
|
||||
if(silent) {
|
||||
optionals += "&disable_notification=" + silent;
|
||||
}
|
||||
|
||||
String q = "chat_id=" + reciver_id + text + optionals + "&disable_web_page_preview=" + no_web_view + "&disable_notification=" + silent + attachment;
|
||||
String q = "chat_id=" + reciver_id + text + optionals + attachment;
|
||||
if(async)
|
||||
return new AsyncSendable(cmd, q, callback, excpt);
|
||||
return new SendableMessage(cmd, q);
|
||||
|
@ -222,8 +228,30 @@ public class MessageBuilder {
|
|||
|
||||
public enum Attachment {
|
||||
none,
|
||||
Video,//video need to be less than 50MB and mp4!
|
||||
Document,
|
||||
Audio,
|
||||
Voice,
|
||||
Photo,
|
||||
Animation;
|
||||
|
||||
public static Attachment getForFileExt(String extention) {
|
||||
if(extention.startsWith("."))
|
||||
extention = extention.substring(1);
|
||||
|
||||
if(extention.equalsIgnoreCase("mp4")) {
|
||||
return Attachment.Video;
|
||||
} else if(extention.equalsIgnoreCase("mp3")) {
|
||||
return Attachment.Audio;
|
||||
} else if(extention.equalsIgnoreCase("ogg")) {
|
||||
return Attachment.Voice;
|
||||
}
|
||||
return Attachment.Document;
|
||||
}
|
||||
|
||||
public static Attachment getForFileName(String name) {
|
||||
return getForFileExt(name.substring(name.lastIndexOf('.')+1));
|
||||
}
|
||||
}
|
||||
|
||||
public class MissingException extends RuntimeException {
|
||||
|
|
|
@ -37,6 +37,7 @@ public class TelegramAPI implements Runnable {
|
|||
|
||||
private static final String API_URL = "https://api.telegram.org/bot";
|
||||
private static final String TOKENREGEX = "^\\d{4,9}:[\\w-]{12,64}$";
|
||||
private static final int TELEGRAMFILESIZELIMIT = 20000000;//20MB filesize https://core.telegram.org/bots/api#sending-files
|
||||
public static final String APIVERSION = "3.7";//February 7, 2019
|
||||
|
||||
private int msg_offset = 0;
|
||||
|
@ -367,6 +368,10 @@ public class TelegramAPI implements Runnable {
|
|||
return fetchedUpdates / ((float) (System.currentTimeMillis() - start) / 1000);
|
||||
}
|
||||
|
||||
public static boolean isSendable(long filesize) {
|
||||
return filesize < TELEGRAMFILESIZELIMIT;
|
||||
}
|
||||
|
||||
public static Callback<JSONObject, TMessage> getCallbackAdapter(TelegramAPI api) {
|
||||
return new Callback<JSONObject, TMessage>() {
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue