Skip to content

Commit

Permalink
Merge pull request #115 from alvin-reyes/master
Browse files Browse the repository at this point in the history
Added SINGLETON and PROTOTYPE State
  • Loading branch information
Alvin Reyes committed Apr 20, 2017
2 parents e655777 + a7eaef7 commit 2f3802d
Show file tree
Hide file tree
Showing 15 changed files with 284 additions and 81 deletions.
47 changes: 10 additions & 37 deletions src/main/java/co/aurasphere/botmill/fb/FbBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import co.aurasphere.botmill.core.BotDefinition;
Expand All @@ -49,14 +47,7 @@
*
*/
public abstract class FbBot implements BotDefinition {


/** The Constant FB_BOTMILL_PAGE_TOKEN. */
private static final String FB_BOTMILL_PAGE_TOKEN = "fb.page.token";

/** The Constant FB_BOTMILL_VALIDATION_TOKEN. */
private static final String FB_BOTMILL_VALIDATION_TOKEN = "fb.validation.token";

/**
* The logger.
*/
Expand All @@ -67,17 +58,14 @@ public abstract class FbBot implements BotDefinition {
* A list of registered {@link FbBotMillEvent} for the current bot.
*/
private List<ActionFrame> actionFrameList;

/**
* The policy this bot follows when processing the callback handler list.
*/
private BotMillPolicy botMillPolicy;

/**
* The bot mill session.
*/
private BotMillSession botMillSession;

/**
* The {@link FbBotMillEvent} object created by this class for each
* annotated method.
Expand Down Expand Up @@ -117,32 +105,17 @@ public FbBot(BotMillPolicy botmillPolicy) {

this.botMillPolicy = botmillPolicy;
this.actionFrameList = new ArrayList<ActionFrame>();
// Create the botmill session.
this.buildFbBotConfig();
this.buildAnnotatedInitBehaviour();

// Registers this bot to the context.

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

FbBotMillContext.getInstance().register(this);

logger.debug("AbstractFbot - End Initialize");
}

/**
* Builds the Fb bot config.
*
* @throws BotMillMissingConfigurationException
* the bot mill missing configuration exception
*/
private void buildFbBotConfig() {

// Everything goes well, initialize the setup.
FbBotMillContext.getInstance().setup(
ConfigurationUtils.getEncryptedConfiguration().getProperty(FB_BOTMILL_PAGE_TOKEN),
ConfigurationUtils.getEncryptedConfiguration().getProperty(FB_BOTMILL_VALIDATION_TOKEN));

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

/**
* Base constructor. Instantiates a bot and registers it to the context.
Expand Down Expand Up @@ -367,11 +340,11 @@ public boolean equals(Object obj) {
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "AbstractFbBot [actionFrameList=" + actionFrameList
+ ", botMillPolicy=" + botMillPolicy + ", botMillSession="
+ botMillSession + ", event=" + event + "]";
}
// @Override
// public String toString() {
// return "AbstractFbBot [actionFrameList=" + actionFrameList
// + ", botMillPolicy=" + botMillPolicy + ", botMillSession="
// + botMillSession + ", event=" + event + "]";
// }

}
17 changes: 17 additions & 0 deletions src/main/java/co/aurasphere/botmill/fb/FbBotApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package co.aurasphere.botmill.fb;

import co.aurasphere.botmill.core.BotDefinition;
import co.aurasphere.botmill.fb.autoreply.AutoReply;

public class FbBotApi {

private static BotDefinition botDefinition;
public static void setFbBot(BotDefinition botDefinition) {
FbBotApi.botDefinition = botDefinition;
}

public static void reply(AutoReply reply) {
((FbBot)botDefinition).reply(reply);
}

}
30 changes: 30 additions & 0 deletions src/main/java/co/aurasphere/botmill/fb/FbBotConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package co.aurasphere.botmill.fb;

import co.aurasphere.botmill.core.internal.util.ConfigurationUtils;

public abstract class FbBotConfiguration {

/** The Constant FB_BOTMILL_PAGE_TOKEN. */
private static final String FB_BOTMILL_PAGE_TOKEN = "fb.page.token";

/** The Constant FB_BOTMILL_VALIDATION_TOKEN. */
private static final String FB_BOTMILL_VALIDATION_TOKEN = "fb.validation.token";

public FbBotConfiguration() {
this.buildFbBotConfig();
}

/**
* Builds the Fb bot config.
*
* @throws BotMillMissingConfigurationException
* the bot mill missing configuration exception
*/
private void buildFbBotConfig() {

FbBotMillContext.getInstance().setup(
ConfigurationUtils.getEncryptedConfiguration().getProperty(FB_BOTMILL_PAGE_TOKEN),
ConfigurationUtils.getEncryptedConfiguration().getProperty(FB_BOTMILL_VALIDATION_TOKEN));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public void registerMonitor(FbBotMillMonitor monitor) {
public List<FbBotMillMonitor> getRegisteredMonitors() {
return this.registeredMonitors;
}

/*
* (non-Javadoc)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@
import co.aurasphere.botmill.fb.internal.util.network.FbBotMillNetworkController;
import co.aurasphere.botmill.fb.model.api.messengerprofile.DeleteMessengerProfileRequest;
import co.aurasphere.botmill.fb.model.api.messengerprofile.Greeting;
import co.aurasphere.botmill.fb.model.api.messengerprofile.HomeUrl;
import co.aurasphere.botmill.fb.model.api.messengerprofile.HomeUrlRequest;
import co.aurasphere.botmill.fb.model.api.messengerprofile.SetAccountLinkingUrlRequest;
import co.aurasphere.botmill.fb.model.api.messengerprofile.SetGetStartedButtonRequest;
import co.aurasphere.botmill.fb.model.api.messengerprofile.SetGreetingTextRequest;
import co.aurasphere.botmill.fb.model.api.messengerprofile.SetWhitelistedDomainsRequest;
import co.aurasphere.botmill.fb.model.api.messengerprofile.persistentmenu.PersistentMenu;
import co.aurasphere.botmill.fb.model.api.messengerprofile.persistentmenu.PersistentMenuRequest;


/**
* Class which handles the configuration of the Facebook Messenger Platform
* Messenger Profile (for more informations, see the link below). The methods of
Expand Down Expand Up @@ -217,6 +218,35 @@ public static void deletePersistentMenus() {
FbBotMillNetworkController.deleteMessengerProfile(request);
}

/**
* This sets the home url of the Bot
*
* @param homeUrl
*
* @see <a href=
* "https://developers.facebook.com/docs/messenger-platform/messenger-profile/home-url/v2.9">
* Chat Extension Home URL</a>
*/
public static void setHomeUrl(HomeUrl homeUrl) {
HomeUrlRequest homeUrlRequest = new HomeUrlRequest();
homeUrlRequest.setHomeUrl(homeUrl);
FbBotMillNetworkController.postMessengerProfile(homeUrlRequest);

}

/**
* Removes the home url.
*
* @see <a href=
* "https://developers.facebook.com/docs/messenger-platform/messenger-profile/home-url/v2.9">
* Chat Extension Home URL</a>
*/
public static void deleteHomeUrl() {
DeleteMessengerProfileRequest request = new DeleteMessengerProfileRequest("home_url");
FbBotMillNetworkController.deleteMessengerProfile(request);

}

/*
* (non-Javadoc)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
* network.
*
* @author Donato Rimenti
* @author Alvin Reyes
*/
public class FbBotMillNetworkController {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package co.aurasphere.botmill.fb.model.api.messengerprofile;

import java.io.Serializable;

import com.google.gson.annotations.SerializedName;

import co.aurasphere.botmill.fb.model.outcoming.template.button.WebViewHeightRatioType;
import co.aurasphere.botmill.fb.model.outcoming.template.button.WebViewShareButton;

public class HomeUrl implements Serializable {

private static final long serialVersionUID = 1L;

private String url;
@SerializedName("webview_height_ratio")
private WebViewHeightRatioType webviewHeightRatio;
@SerializedName("webview_share_button")
private WebViewShareButton webviewShareButton;
@SerializedName("in_test")
private boolean inTest;

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public WebViewHeightRatioType getWebviewHeightRatio() {
return webviewHeightRatio;
}

public void setWebviewHeightRatio(WebViewHeightRatioType webviewHeightRatio) {
this.webviewHeightRatio = webviewHeightRatio;
}

public WebViewShareButton getWebviewShareButton() {
return webviewShareButton;
}

public void setWebviewShareButton(WebViewShareButton webviewShareButton) {
this.webviewShareButton = webviewShareButton;
}

public boolean isInTest() {
return inTest;
}

public void setInTest(boolean inTest) {
this.inTest = inTest;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package co.aurasphere.botmill.fb.model.api.messengerprofile;

import com.google.gson.annotations.SerializedName;

public class HomeUrlRequest {

@SerializedName("home_url")
private HomeUrl homeUrl;

public HomeUrl getHomeUrl() {
return homeUrl;
}

public void setHomeUrl(HomeUrl homeUrl) {
this.homeUrl = homeUrl;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
*
* The Persistent Menu Request is the main object we sent thru our post request which will
* create the necessary JSON structured data to create the persistent menu of the bots
*
* @author Alvin P. Reyes
*
*/
public class PersistentMenuRequest implements Serializable {
Expand Down
Loading

0 comments on commit 2f3802d

Please sign in to comment.