javaflock is a java client for FlockOS.
Add the JitPack repository to your build file
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>Add the dependency
<dependency>
<groupId>com.flock</groupId>
<artifactId>javaflock</artifactId>
<version>v1.1</version>
</dependency>Add the JitPack repository to your root build.gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}Add the dependency
dependencies {
compile 'com.flock:javaflock:v1.1'
}UidResponse messageId = Chat.sendMessage("token", "<to>", "<message>", null);ListenableFuture<UidResponse> future = Chat.sendMessageAsync("token", "<to>", "<message>", null);SendAs sendAs = new SendAs().name("HAL-9000").profileImage("https://pbs.twimg.com/profile_images/1788506913/HAL-MC2_400x400.png");
Chat.sendMessage("token", "<to>", "<message>", new SendMessageOptionalParams().sendAs(sendAs));WidgetView widget = new WidgetView().src("http://example.com").height(250);
Views views = new Views().widget(widget);
Attachment attachment = new Attachment().title("Test widget").description("<description>").views(views);
// NOTE: attachments is a list of attachments
Chat.sendMessage("<token>", "<to>", "<message>", new SendMessageOptionalParams().attachments(Collections.singletonList(attachment)));HtmlView htmlView = new HtmlView().inline("A valid <b>html</b> here").height(50);
Views views = new Views().html(htmlView);
Attachment attachment = new Attachment().title("Test html").description("<description>").views(views);
Chat.sendMessage("<token>", "<to>", "<message>", new SendMessageOptionalParams().attachments(Collections.singletonList(attachment)));Views views = new Views().flockml("<flockml>FlockML is <b>AWESOME</b></flockml>");
Attachment attachment = new Attachment().title("Test flockml").description("<description>").views(views);
Chat.sendMessage("<token>", "<to>", "<message>", new SendMessageOptionalParams().attachments(Collections.singletonList(attachment)));Image image = new Image().src("http://library.acropolis.org/wp-content/uploads/2014/11/One_ring.png").width(400).height(400);
ImageView imageView = new ImageView().original(image).filename("onering.png");
Views views = new Views().image(imageView)
Attachment attachment = new Attachment().title("Test imageview").description("<description>").views(views);
Chat.sendMessage("<token>", "<to>", "<message>", new SendMessageOptionalParams().attachments(Collections.singletonList(attachment)));AttachmentDownload attachmentDownload = new AttachmentDownload().src("http://wallpapercave.com/wp/H630T6R.jpg");
Views views = new Views().flockml("<flockml>Download the <i>matrix</i></flockml>")
// NOTE: downloads is always a list
Attachment attachment = new Attachment().title("Test file").downloads(Collections.singletonList(attachmentDownload)).views(views);
Chat.sendMessage("<token>", "<to>", "<message>", new SendMessageOptionalParams().attachments(Collections.singletonList(attachment)));AttachmentButton b1 = new AttachmentButton().name("Harry Potter").id("harry").action(new ActionConfig().type("openWidget").url("https://goo.gl/aygRGf").desktopType("sidebar"));
AttachmentButton b2 = new AttachmentButton().name("Ron Weasley").id("ron").action(new ActionConfig().type("openBrowser").url("https://goo.gl/gDpMVn").sendContext(true));
AttachmentButton b3 = new AttachmentButton().name("Hermione Granger").id("hermione").action(new ActionConfig().type("sendEvent"));
Attachment attachment = new Attachment().title("Test buttons").buttons(Arrays.asList(b1,b2,b3));
Chat.sendMessage("<token>", "<to>", "Who is your favourite Harry Potter character?", new SendMessageOptionalParams().attachments(Collections.singletonList(attachment)));Attachment attachment = new Attachment().title("Test colour").color("#FF0000").description("It is red!");
Chat.sendMessage("<token>", "<to>", "<message>", new SendMessageOptionalParams().attachments(Collections.singletonList(attachment)));Message[] messages = Chat.fetchMessages("<token>", "<chat>", uids);Channel channel = Channels.getInfo("<token>", channelId);PublicProfile[] members = Channels.getMembers("<token>", channelId);Channel[] channelList = Channels.list("<token>");User userInfo = Users.getInfo("<token>");User userInfo = Users.getPublicProfile("<token>", userId);PublicProfile[] contacts = Roster.listContacts("<token>");Handling events
Create instance of EventHandlerClient
EventHandlerClient client = new EventHandlerClient("<appID>", "<appSecret>");Attach eventListeners with the client (these will be fired when an event occurs)
client.setAppInstallListener(event -> {
// handle app install event here
});
client.setClientSlashCommandListener(event -> {
// handle slash command event here
...
// return the response for the event
return new ToastMessage().text("<toast message to be shown>");
});Attach eventHandlerClient with your web framework by calling client.handleRequest when event request is received
HttpServletResponse response = client.handleRequest(request, response);Verifying event token
TokenVerifier tokenVerifier = new TokenVerifier("<appId>", "<appSecret>");
boolean isTokenVerified = tokenVerifier.verifyToken("<eventToken>", "<userId>");