daniel-sc / rocketchat-modern-client

Client SDK for https://rocket.chat employing reactive style.
MIT License
11 stars 11 forks source link

Add support for "Attachment" and "Attachment Field". #4

Closed tuxmartin closed 5 years ago

tuxmartin commented 5 years ago

Hi, I'm trying to add support for Attachment and Attachment Field.

Attachment works, but I don't know how to create POJO class for Attachment Field object.

Attachment Field object needs param short, which is Java reserved word. If I rename it to _short, it doesn't work.

https://rocket.chat/docs/developer-guides/rest-api/chat/postmessage/#attachment-field-objects

package com.github.daniel_sc.rocketchat.modern_client.request;
public class AttachmentField {
    public final boolean _short = false;
    public final String title;
    public final String value;

    public AttachmentField(boolean _short, String title, String value) {
        this._short = _short;
        this.title = title;
        this.value = value;
    }       
}

I nees something like convert _short to short before sending.

I don't have no idea how to do it :-(

My testing code:

List<Attachment> attachments = new ArrayList<Attachment>();

Attachment a1 = new Attachment();       
a1.setColor("#0000ff");
a1.setText("Test attachment message\nand next line wit **mark-down** formatting...");
a1.setAuthor_name("tuxmartin");
a1.setAuthor_icon("https://avatars2.githubusercontent.com/u/1219067?s=400&v=4");
a1.setAuthor_link("https://github.com/tuxmartin");
a1.setTitle("Attachment test A1");
a1.setTitle_link("https://www.google.com/?q=Attachment%20test%20A1");
attachments.add(a1);

Attachment a2 = new Attachment();
a2.setImage_url("https://github.githubassets.com/images/icons/emoji/unicode/1f334.png");        
attachments.add(a2);

Attachment a3 = new Attachment();
a3.setColor("#00FF00");
a3.setTitle("Project status");      
List<AttachmentField> attachmentFields = new ArrayList<>();
AttachmentField af1 = new AttachmentField("Status", "New");
attachmentFields.add(af1);
AttachmentField af2 = new AttachmentField("Priority", "High");
attachmentFields.add(af2);      
a3.setAttachmentFields(attachmentFields);
attachments.add(a3);

String messageId = rocketChat.sendMsg("Test message", testChannelRoomId, "JAVA APP TEST", coffeImg, attachments);

produces: https://ctrlv.cz/shots/2019/02/22/lSeB.png (print screen)

but I need something like this: https://raw.githubusercontent.com/scantem/redmine_rocketchat/assets/screenshot.png

as you can see, a3 AttachmentField are not working.

Thanks for help!

coveralls commented 5 years ago

Coverage Status

Coverage decreased (-24.4%) to 68.327% when pulling dfc0bb7d248e76b7391e4736fa6a6c18cffd71e1 on tuxmartin:attachments into b4baf56a9486eb2b95b260273be270de4201c484 on daniel-sc:master.

daniel-sc commented 5 years ago

I‘ll look into this tomorrow - could you please resolve the merge conflict meanwhile?

daniel-sc commented 5 years ago

@tuxmartin to solve the problem with short: We use GSON to serialize the POJOs to JSON so you can use @SerializedName("short") to get the desired result - see as well: https://github.com/google/gson/blob/master/UserGuide.md#json-field-naming-support

tuxmartin commented 5 years ago

@daniel-sc thank you. @SerializedName("short") works great.