All Downloads are FREE. Search and download functionalities are using the official Maven repository.

co.aurasphere.botmill.fb.threadsettings.FbBotMillThreadSettingsConfiguration Maven / Gradle / Ivy

There is a newer version: 2.0.0-RC3
Show newest version
/*
 * MIT License
 *
 * Copyright (c) 2016 BotMill.io
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package co.aurasphere.botmill.fb.threadsettings;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import co.aurasphere.botmill.core.BotDefinition;
import co.aurasphere.botmill.fb.internal.util.network.FbBotMillNetworkController;
import co.aurasphere.botmill.fb.model.outcoming.template.button.Button;
import co.aurasphere.botmill.fb.model.outcoming.template.button.ButtonType;
import co.aurasphere.botmill.fb.model.outcoming.template.button.BuyButton;
import co.aurasphere.botmill.fb.model.outcoming.template.button.PaymentSummary;
import co.aurasphere.botmill.fb.model.outcoming.template.button.PostbackButton;
import co.aurasphere.botmill.fb.model.outcoming.template.button.WebUrlButton;
import co.aurasphere.botmill.fb.model.threadsettings.CallToActionsRequest;
import co.aurasphere.botmill.fb.model.threadsettings.DomainActionType;
import co.aurasphere.botmill.fb.model.threadsettings.ThreadState;
import co.aurasphere.botmill.fb.model.threadsettings.WhitelistDomainRequest;
import co.aurasphere.botmill.fb.model.threadsettings.greeting.SetGreetingTextRequest;
import co.aurasphere.botmill.fb.model.threadsettings.payment.PaymentDevModeAction;
import co.aurasphere.botmill.fb.model.threadsettings.payment.PaymentSettings;

/**
 * Class which handles the configuration of the Facebook Messenger Platform
 * Thread Settings (for more informations, see the link below). The methods of
 * this class needs to be called only once and thus shouldn't be put on the
 * class that implements {@link BotDefinition}. The best way of handling the
 * configuration would be defining your own class with a main method and put the
 * call on it.
 *
 * @author Donato Rimenti
 * @see Facebook's Thread Settings Documentation
 */
public class FbBotMillThreadSettingsConfiguration {

	/**
	 * The logger.
	 */
	private static final Logger logger = LoggerFactory
			.getLogger(FbBotMillThreadSettingsConfiguration.class);

	/**
	 * Instantiates a new FbBotMillThreadSettingsConfiguration.
	 */
	private FbBotMillThreadSettingsConfiguration() {
	}

	/**
	 * This method is used to add any payment settings needed.
	 * 
	 * @param paymentSettings
	 *            the payment settings object.
	 * @see Payments settings
	 */
	public static void addPaymentSettings(PaymentSettings paymentSettings) {
		if (paymentSettings == null) {
			logger.error("FbBotMill validation error: Payment Settings can't be null or empty!");
			return;
		}
		FbBotMillNetworkController.postThreadSetting(paymentSettings);
	}

	/**
	 * Sets the greeting message for the bot. The Greeting Text is only rendered
	 * the first time the user interacts with a the Page on Messenger.
	 *
	 * @param message
	 *            the greeting message to show.
	 * @see Facebook's Greeting Text Documentation
	 */
	public static void setGreetingMessage(String message) {
		if (message == null || "".equals(message)) {
			logger.error("FbBotMill validation error: Greeting message can't be null or empty!");
			return;
		}
		SetGreetingTextRequest request = new SetGreetingTextRequest(message);
		FbBotMillNetworkController.postThreadSetting(request);
	}

	/**
	 * Sets the Get Started Button for the bot. The Get Started button is only
	 * rendered the first time the user interacts with a the Page on Messenger.
	 * When this button is tapped, the defined payload will be sent back with a
	 * postback received callback.
	 *
	 * @param payload
	 *            the payload to return when the button is tapped.
	 * @see Facebook's Get Started Button Documentation
	 */
	public static void setGetStartedButton(String payload) {
		if (payload == null || "".equals(payload)) {
			logger.error("FbBotMill validation error: Get Started Button payload can't be null or empty!");
			return;
		}
		Button button = new PostbackButton(null, ButtonType.POSTBACK, payload);
		List




© 2015 - 2024 Weber Informatics LLC | Privacy Policy