Skip to content

Commit

Permalink
Merge pull request #119 from alvin-reyes/master
Browse files Browse the repository at this point in the history
Added features for Events, Thread Handling and Security
  • Loading branch information
Alvin Reyes authored May 13, 2017
2 parents 2f3802d + 0899f6d commit a422b8e
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 80 deletions.
2 changes: 0 additions & 2 deletions src/main/java/co/aurasphere/botmill/fb/FbBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import co.aurasphere.botmill.core.BotDefinition;
import co.aurasphere.botmill.core.BotMillPolicy;
import co.aurasphere.botmill.core.BotMillSession;
import co.aurasphere.botmill.core.internal.util.ConfigurationUtils;
import co.aurasphere.botmill.fb.actionframe.ActionFrame;
import co.aurasphere.botmill.fb.autoreply.AutoReply;
import co.aurasphere.botmill.fb.event.FbBotMillEvent;
Expand Down Expand Up @@ -109,7 +108,6 @@ public FbBot(BotMillPolicy botmillPolicy) {


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

FbBotMillContext.getInstance().register(this);

Expand Down
25 changes: 24 additions & 1 deletion src/main/java/co/aurasphere/botmill/fb/FbBotApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,38 @@
import co.aurasphere.botmill.core.BotDefinition;
import co.aurasphere.botmill.fb.autoreply.AutoReply;

/**
* The Class FbBotApi.
*/
public class FbBotApi {

/** The bot definition. */
private static BotDefinition botDefinition;

/**
* Sets the fb bot.
*
* @param botDefinition the new fb bot
*/
public static void setFbBot(BotDefinition botDefinition) {
FbBotApi.botDefinition = botDefinition;
}

/**
* Reply.
*
* @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 AccountLinkingEvent extends FbBotMillBean implements FbBotMillEvent {

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

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

/*
* (non-Javadoc)
*
* @see co.aurasphere.botmill.fb.bean.FbBotMillBean#toString()
*/
@Override
public String toString() {
return "AccountLinking []";
}
}
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 @@ -113,5 +113,8 @@
* @return the string
*/
String meta() default ""; // random text to indicate the purpose.


boolean skipAuthorization() default false;

}
Loading

0 comments on commit a422b8e

Please sign in to comment.