message Builder with encoded url

This commit is contained in:
MrBesen 2019-02-11 16:38:05 +01:00
parent c971c05de3
commit 61527b9737
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
1 changed files with 12 additions and 4 deletions

View File

@ -98,13 +98,21 @@ public class MessageBuilder {
throw new IllegalArgumentException("attachment empty!"); throw new IllegalArgumentException("attachment empty!");
} }
attachmenttype = type; attachmenttype = type;
attachment = cont; try {
attachment = URLEncoder.encode(cont, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return this; return this;
} }
public MessageBuilder setCaption(String text) { public MessageBuilder setCaption(String text) {
this.caption = text; try {
this.caption = URLEncoder.encode(text, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return this; return this;
} }
@ -130,10 +138,10 @@ public class MessageBuilder {
String cmd; String cmd;
String text = ""; String text = "";
if(attachmenttype != Attachment.none) { if(attachmenttype != Attachment.none) {
attachment = "&" + attachmenttype.name().toLowerCase() + "=" + this.attachment;
cmd = "send" + attachmenttype.name();
if(caption != null) if(caption != null)
attachment += "&caption=" + caption; attachment += "&caption=" + caption;
attachment = "&" + attachmenttype.name().toLowerCase() + "=" + this.attachment;
cmd = "send" + attachmenttype.name();
} else { } else {
cmd = "sendMessage"; cmd = "sendMessage";
if(this.text != null) { if(this.text != null) {