Skip to content

Commit d7c5b6d

Browse files
author
Alvin Reyes
committed
Initial version. Mostly models and ugly webhook coding. Further modification will be done of course.
0 parents  commit d7c5b6d

18 files changed

Lines changed: 2155 additions & 0 deletions

File tree

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.classpath
2+
.project
3+
.settings/
4+
/bin/
5+
/target/
6+
7+
/target/
8+
dependency-reduced-pom.xml

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2016 BotMill
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Kik-BotMill
2+
A Java framework for building bots on Kik.

pom.xml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<version>1.0-SNAPSHOT</version>
5+
<name>kik-botmill</name>
6+
<build>
7+
<sourceDirectory>src</sourceDirectory>
8+
<plugins>
9+
<plugin>
10+
<artifactId>maven-compiler-plugin</artifactId>
11+
<version>3.3</version>
12+
<configuration>
13+
<source>1.8</source>
14+
<target>1.8</target>
15+
</configuration>
16+
</plugin>
17+
<plugin>
18+
<groupId>org.apache.maven.plugins</groupId>
19+
<artifactId>maven-shade-plugin</artifactId>
20+
<executions>
21+
<execution>
22+
<phase>package</phase>
23+
<goals>
24+
<goal>shade</goal>
25+
</goals>
26+
</execution>
27+
</executions>
28+
</plugin>
29+
</plugins>
30+
</build>
31+
<artifactId>kik-botmill</artifactId>
32+
<groupId>co.aurasphere.botmill</groupId>
33+
<dependencies>
34+
<dependency>
35+
<groupId>com.google.guava</groupId>
36+
<artifactId>guava</artifactId>
37+
<version>20.0</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>com.google.code.gson</groupId>
41+
<artifactId>gson</artifactId>
42+
<version>2.8.0</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.apache.httpcomponents</groupId>
46+
<artifactId>httpclient</artifactId>
47+
<version>4.5.2</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.slf4j</groupId>
51+
<artifactId>slf4j-api</artifactId>
52+
<version>1.7.21</version>
53+
</dependency>
54+
<dependency>
55+
<groupId>ch.qos.logback</groupId>
56+
<artifactId>logback-classic</artifactId>
57+
<version>1.0.13</version>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.hibernate</groupId>
61+
<artifactId>hibernate-validator</artifactId>
62+
<version>5.2.4.Final</version>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.glassfish.web</groupId>
66+
<artifactId>javax.el</artifactId>
67+
<version>2.2.4</version>
68+
</dependency>
69+
<dependency>
70+
<groupId>com.sparkjava</groupId>
71+
<artifactId>spark-core</artifactId>
72+
<version>2.5</version>
73+
</dependency>
74+
75+
<dependency>
76+
<groupId>org.springframework</groupId>
77+
<artifactId>spring-core</artifactId>
78+
<version>4.1.6.RELEASE</version>
79+
</dependency>
80+
<dependency>
81+
<groupId>org.springframework</groupId>
82+
<artifactId>spring-context</artifactId>
83+
<version>4.1.6.RELEASE</version>
84+
</dependency>
85+
<dependency>
86+
<groupId>org.springframework</groupId>
87+
<artifactId>spring-beans</artifactId>
88+
<version>4.1.6.RELEASE</version>
89+
</dependency>
90+
<dependency>
91+
<groupId>org.springframework</groupId>
92+
<artifactId>spring-jdbc</artifactId>
93+
<version>4.1.6.RELEASE</version>
94+
</dependency>
95+
<dependency>
96+
<groupId>junit</groupId>
97+
<artifactId>junit</artifactId>
98+
<version>3.8.1</version>
99+
<scope>test</scope>
100+
</dependency>
101+
<dependency>
102+
<groupId>org.apache.httpcomponents</groupId>
103+
<artifactId>httpmime</artifactId>
104+
<version>4.5.2</version>
105+
</dependency>
106+
<dependency>
107+
<groupId>org.alicebot.ab</groupId>
108+
<artifactId>ab</artifactId>
109+
<version>4.0.4-SNAPSHOT</version>
110+
</dependency>
111+
<dependency>
112+
<groupId>junit</groupId>
113+
<artifactId>junit</artifactId>
114+
<version>3.8.1</version>
115+
<scope>test</scope>
116+
</dependency>
117+
</dependencies>
118+
</project>
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
package co.aurasphere.botmill.kik.model;
2+
3+
import java.util.ArrayList;
4+
import com.google.gson.JsonArray;
5+
import com.google.gson.JsonObject;
6+
7+
/**
8+
* The Class Chat.
9+
*/
10+
public class Chat {
11+
12+
/** The from. */
13+
private String chatId, from;
14+
15+
/** The participants. */
16+
private ArrayList<User> participants = new ArrayList<User>();
17+
18+
/** The kik api. */
19+
private KikApi kikApi;
20+
21+
/**
22+
* Instantiates a new chat.
23+
*
24+
* @param chatId
25+
* the chat id
26+
* @param participants
27+
* the participants
28+
* @param from
29+
* the from
30+
* @param kikApi
31+
* the kik api
32+
*/
33+
public Chat(String chatId, ArrayList<User> participants, String from, KikApi kikApi) {
34+
this.chatId = chatId;
35+
this.participants = participants;
36+
this.from = from;
37+
this.kikApi = kikApi;
38+
}
39+
40+
/**
41+
* Gets the chat id.
42+
*
43+
* @return the chat id
44+
*/
45+
public String getChatId() {
46+
return chatId;
47+
}
48+
49+
/**
50+
* Gets the from.
51+
*
52+
* @return the from
53+
*/
54+
public String getFrom() {
55+
return from;
56+
}
57+
58+
/**
59+
* Gets the participants.
60+
*
61+
* @return the participants
62+
*/
63+
public ArrayList<User> getParticipants() {
64+
return participants;
65+
}
66+
67+
/**
68+
* Send message.
69+
*
70+
* @param msgs
71+
* the msgs
72+
*/
73+
public void sendMessage(Message... msgs) {
74+
JsonObject msgObject = new JsonObject();
75+
JsonArray msgArray = new JsonArray();
76+
77+
for (int i = 0; i < msgs.length; i++) {
78+
JsonObject msg = new JsonObject();
79+
80+
msg.addProperty("chatId", chatId);
81+
msg.addProperty("type", msgs[i].getType());
82+
msg.addProperty("to", from);
83+
84+
if (msgs[i].hasKeyboard()) {
85+
msg.add("keyboards", msgs[i].getKeyboard().getKeyboardJson());
86+
}
87+
88+
switch (msgs[i].getType()) {
89+
case Message.Type.IMAGE:
90+
msg.addProperty("picUrl", msgs[i].getBody());
91+
break;
92+
93+
case Message.Type.URL:
94+
msg.addProperty("url", msgs[i].getBody());
95+
break;
96+
97+
case Message.Type.VIDEO:
98+
msg.addProperty("videoUrl", msgs[i].getBody());
99+
break;
100+
101+
default:
102+
if (msgs[i].getBody().isEmpty()) {
103+
System.out.println("Message " + i + "'s body was empty, it had the type of " + msgs[i].getType());
104+
105+
continue;
106+
}
107+
msg.addProperty("body", msgs[i].getBody());
108+
break;
109+
}
110+
111+
if (msgs[i].getTypeTime() > 0) {
112+
msg.addProperty("typeTime", msgs[i].getTypeTime());
113+
}
114+
115+
msgArray.add(msg);
116+
}
117+
118+
msgObject.add("messages", msgArray);
119+
120+
try {
121+
kikApi.send(KikBotMillConstants.MESSAGE_ENDPOINT, msgObject.toString(), "post");
122+
} catch (Exception e) {
123+
e.printStackTrace();
124+
}
125+
}
126+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package co.aurasphere.botmill.kik.model;
2+
3+
import java.io.File;
4+
5+
/**
6+
* The Class FileMessage.
7+
*/
8+
public class FileMessage extends Message {
9+
10+
/**
11+
* Instantiates a new file message.
12+
*
13+
* @param file
14+
* the file
15+
* @param api
16+
* the api
17+
* @param type
18+
* the type
19+
* @param typeTime
20+
* the type time
21+
*/
22+
public FileMessage(File file, KikApi api, String type, int typeTime) {
23+
super("", type, typeTime);
24+
25+
try {
26+
String fileMD5 = Utils.calculateFileMD5(file);
27+
28+
api.getListenerThread().getFileMap().put(fileMD5, file);
29+
System.out.println("Registerd new file " + fileMD5 + " => " + file);
30+
31+
String url = "http://" + Utils.getPublicIP() + ":" + api.getPort() + "/" + fileMD5;
32+
33+
this.setBody(url);
34+
this.setPictureUrl(url);
35+
} catch (Exception e) {
36+
e.printStackTrace();
37+
}
38+
}
39+
40+
}

0 commit comments

Comments
 (0)