Skip to content

Commit

Permalink
Added Referral Event
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvin Reyes committed May 13, 2017
1 parent 6afead9 commit 0899f6d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/main/java/co/aurasphere/botmill/fb/FbBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public FbBot(BotMillPolicy botmillPolicy) {


// Create the botmill session.
botMillSession = BotMillSession.getInstance();

FbBotMillContext.getInstance().register(this);

Expand Down
10 changes: 9 additions & 1 deletion src/main/java/co/aurasphere/botmill/fb/FbBotApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ public static void setFbBot(BotDefinition botDefinition) {
* @param reply the reply
*/
public static void reply(AutoReply reply) {
((FbBot)botDefinition).reply(reply);
if(FbBotApi.botDefinition == null) {
botDefinition = new FbBotApiBot();
}
((FbBot)FbBotApi.botDefinition).reply(reply);
}


}
class FbBotApiBot extends FbBot implements BotDefinition {
public FbBotApiBot() {
}
}
6 changes: 1 addition & 5 deletions src/main/java/co/aurasphere/botmill/fb/FbBotMillServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {

logger.trace("POST received!");
MessengerCallback callback = null;
MessengerCallback callback = new MessengerCallback();

// Extrapolates and logs the JSON for debugging.
String json = readerToString(req.getReader());
Expand All @@ -175,10 +175,6 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
if (envelopes != null) {
MessageEnvelope lastEnvelope = envelopes.get(envelopes.size() - 1);
IncomingToOutgoingMessageHandler.getInstance().process(lastEnvelope);
// for (FbBot bot : FbBotMillContext.getInstance()
// .getRegisteredBots()) {
// bot.processMessage(lastEnvelope);
// }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package co.aurasphere.botmill.fb.event.account;

import co.aurasphere.botmill.fb.bean.FbBotMillBean;
import co.aurasphere.botmill.fb.event.FbBotMillEvent;
import co.aurasphere.botmill.fb.event.FbBotMillEventType;
import co.aurasphere.botmill.fb.model.incoming.MessageEnvelope;

public class ReferralEvent extends FbBotMillBean implements FbBotMillEvent {

/**
* Instantiates a new LocationEvent.
*/
public ReferralEvent() {
}

public final boolean verifyEventCondition(MessageEnvelope envelope) {
return eventKind(envelope) == FbBotMillEventType.REFERRAL;
}

/*
* (non-Javadoc)
*
* @see co.aurasphere.botmill.fb.bean.FbBotMillBean#toString()
*/
@Override
public String toString() {
return "ReferralEvent []";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import co.aurasphere.botmill.fb.event.FbBotMillEvent;
import co.aurasphere.botmill.fb.event.FbBotMillEventType;
import co.aurasphere.botmill.fb.event.account.AccountLinkingEvent;
import co.aurasphere.botmill.fb.event.account.ReferralEvent;
import co.aurasphere.botmill.fb.event.media.AudioEvent;
import co.aurasphere.botmill.fb.event.media.FileEvent;
import co.aurasphere.botmill.fb.event.media.ImageEvent;
Expand Down Expand Up @@ -83,6 +84,7 @@ public static IncomingToOutgoingMessageHandler getInstance() {
if (instance == null) {
instance = new IncomingToOutgoingMessageHandler();
}
instance = new IncomingToOutgoingMessageHandler();
return instance;
}

Expand Down Expand Up @@ -113,7 +115,7 @@ private void handleOutgoingMessage(MessageEnvelope message) {
Bot botClass = defClass.getClass().getAnnotation(Bot.class);
if (botClass.state().equals(BotBeanState.PROTOTYPE)) {
try {
defClass.getClass().newInstance();
defClass = defClass.getClass().newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
Expand Down Expand Up @@ -282,6 +284,8 @@ private FbBotMillEvent toEventActionFrame(FbBotMillController botMillController)
} else {
throw new BotMillEventMismatchException("quickpayload pattern attribute missing");
}
case REFERRAL:
return new ReferralEvent();
case ACCOUNT_LINKING:
return new AccountLinkingEvent();
case LOCATION:
Expand Down

0 comments on commit 0899f6d

Please sign in to comment.