Skip to content

Commit 0899f6d

Browse files
author
Alvin Reyes
committed
Added Referral Event
1 parent 6afead9 commit 0899f6d

File tree

5 files changed

+44
-8
lines changed

5 files changed

+44
-8
lines changed

src/main/java/co/aurasphere/botmill/fb/FbBot.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ public FbBot(BotMillPolicy botmillPolicy) {
108108

109109

110110
// Create the botmill session.
111-
botMillSession = BotMillSession.getInstance();
112111

113112
FbBotMillContext.getInstance().register(this);
114113

src/main/java/co/aurasphere/botmill/fb/FbBotApi.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ public static void setFbBot(BotDefinition botDefinition) {
2626
* @param reply the reply
2727
*/
2828
public static void reply(AutoReply reply) {
29-
((FbBot)botDefinition).reply(reply);
29+
if(FbBotApi.botDefinition == null) {
30+
botDefinition = new FbBotApiBot();
31+
}
32+
((FbBot)FbBotApi.botDefinition).reply(reply);
3033
}
3134

35+
36+
}
37+
class FbBotApiBot extends FbBot implements BotDefinition {
38+
public FbBotApiBot() {
39+
}
3240
}

src/main/java/co/aurasphere/botmill/fb/FbBotMillServlet.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
151151
throws ServletException, IOException {
152152

153153
logger.trace("POST received!");
154-
MessengerCallback callback = null;
154+
MessengerCallback callback = new MessengerCallback();
155155

156156
// Extrapolates and logs the JSON for debugging.
157157
String json = readerToString(req.getReader());
@@ -175,10 +175,6 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
175175
if (envelopes != null) {
176176
MessageEnvelope lastEnvelope = envelopes.get(envelopes.size() - 1);
177177
IncomingToOutgoingMessageHandler.getInstance().process(lastEnvelope);
178-
// for (FbBot bot : FbBotMillContext.getInstance()
179-
// .getRegisteredBots()) {
180-
// bot.processMessage(lastEnvelope);
181-
// }
182178
}
183179
}
184180
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package co.aurasphere.botmill.fb.event.account;
2+
3+
import co.aurasphere.botmill.fb.bean.FbBotMillBean;
4+
import co.aurasphere.botmill.fb.event.FbBotMillEvent;
5+
import co.aurasphere.botmill.fb.event.FbBotMillEventType;
6+
import co.aurasphere.botmill.fb.model.incoming.MessageEnvelope;
7+
8+
public class ReferralEvent extends FbBotMillBean implements FbBotMillEvent {
9+
10+
/**
11+
* Instantiates a new LocationEvent.
12+
*/
13+
public ReferralEvent() {
14+
}
15+
16+
public final boolean verifyEventCondition(MessageEnvelope envelope) {
17+
return eventKind(envelope) == FbBotMillEventType.REFERRAL;
18+
}
19+
20+
/*
21+
* (non-Javadoc)
22+
*
23+
* @see co.aurasphere.botmill.fb.bean.FbBotMillBean#toString()
24+
*/
25+
@Override
26+
public String toString() {
27+
return "ReferralEvent []";
28+
}
29+
}

src/main/java/co/aurasphere/botmill/fb/model/incoming/handler/IncomingToOutgoingMessageHandler.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import co.aurasphere.botmill.fb.event.FbBotMillEvent;
4040
import co.aurasphere.botmill.fb.event.FbBotMillEventType;
4141
import co.aurasphere.botmill.fb.event.account.AccountLinkingEvent;
42+
import co.aurasphere.botmill.fb.event.account.ReferralEvent;
4243
import co.aurasphere.botmill.fb.event.media.AudioEvent;
4344
import co.aurasphere.botmill.fb.event.media.FileEvent;
4445
import co.aurasphere.botmill.fb.event.media.ImageEvent;
@@ -83,6 +84,7 @@ public static IncomingToOutgoingMessageHandler getInstance() {
8384
if (instance == null) {
8485
instance = new IncomingToOutgoingMessageHandler();
8586
}
87+
instance = new IncomingToOutgoingMessageHandler();
8688
return instance;
8789
}
8890

@@ -113,7 +115,7 @@ private void handleOutgoingMessage(MessageEnvelope message) {
113115
Bot botClass = defClass.getClass().getAnnotation(Bot.class);
114116
if (botClass.state().equals(BotBeanState.PROTOTYPE)) {
115117
try {
116-
defClass.getClass().newInstance();
118+
defClass = defClass.getClass().newInstance();
117119
} catch (InstantiationException e) {
118120
e.printStackTrace();
119121
} catch (IllegalAccessException e) {
@@ -282,6 +284,8 @@ private FbBotMillEvent toEventActionFrame(FbBotMillController botMillController)
282284
} else {
283285
throw new BotMillEventMismatchException("quickpayload pattern attribute missing");
284286
}
287+
case REFERRAL:
288+
return new ReferralEvent();
285289
case ACCOUNT_LINKING:
286290
return new AccountLinkingEvent();
287291
case LOCATION:

0 commit comments

Comments
 (0)