Search in sources :

Example 1 with FbBotMillResponse

use of co.aurasphere.botmill.fb.model.outcoming.FbBotMillResponse in project fb-botmill by BotMill.

the class AnnotatedTemplatedBehaviourTest method catchTextAndReplyWithImage.

@FbBotMillController(eventType = FbBotMillEventType.MESSAGE, text = "Hi with Image!", caseSensitive = true)
public void catchTextAndReplyWithImage(MessageEnvelope envelope) {
    //		
    UploadAttachmentResponse response = UploadApi.uploadAttachment(AttachmentType.IMAGE, "http://vignette2.wikia.nocookie.net/nickelodeon/images/2/27/Spongebob_PNG.png/revision/latest?cb=20120702055752");
    String attachmentId = response.getAttachmentId();
    reply(new AutoReply() {

        @Override
        public FbBotMillResponse createResponse(MessageEnvelope envelope) {
            String greetingMessage = "Hey There! ";
            return ReplyFactory.addTextMessageOnly(greetingMessage).build(envelope);
        }
    });
}
Also used : MessageAutoReply(co.aurasphere.botmill.fb.autoreply.MessageAutoReply) AutoReply(co.aurasphere.botmill.fb.autoreply.AutoReply) FbBotMillResponse(co.aurasphere.botmill.fb.model.outcoming.FbBotMillResponse) UploadAttachmentResponse(co.aurasphere.botmill.fb.model.api.upload.UploadAttachmentResponse) MessageEnvelope(co.aurasphere.botmill.fb.model.incoming.MessageEnvelope) FbBotMillController(co.aurasphere.botmill.fb.model.annotation.FbBotMillController)

Example 2 with FbBotMillResponse

use of co.aurasphere.botmill.fb.model.outcoming.FbBotMillResponse in project fb-botmill by BotMill.

the class BuyButtonTest method defineBehaviour.

/*
	 * (non-Javadoc)
	 * 
	 * @see co.aurasphere.botmill.fb.FbBotDefinition#defineBehavior()
	 */
public void defineBehaviour() {
    // loads the annotated encryption class.
    ConfigurationUtils.loadEncryptedConfigurationProperties();
    // loads the annotated bot.
    ConfigurationUtils.loadBotDefinitions();
    addActionFrame(new MessageEvent(MESSAGE_TO_SEND), new AutoReply() {

        @Override
        public FbBotMillResponse createResponse(MessageEnvelope envelope) {
            return ReplyFactory.addGenericTemplate().addElement("A simple Button Template with a Buy Button").addButton(ButtonFactory.createBuyButton("buy_button_payload").setPaymentSummary("USD", PaymentType.FIXED_AMOUNT, "BotMill.io").addPriceLabel("A price label", "2").setTestPayment(true).addRequestedUserInfo(RequestedUserInfo.CONTACT_PHONE).build()).endElement().build(envelope);
        }
    });
}
Also used : AutoReply(co.aurasphere.botmill.fb.autoreply.AutoReply) FbBotMillResponse(co.aurasphere.botmill.fb.model.outcoming.FbBotMillResponse) MessageEvent(co.aurasphere.botmill.fb.event.message.MessageEvent) MessageEnvelope(co.aurasphere.botmill.fb.model.incoming.MessageEnvelope)

Example 3 with FbBotMillResponse

use of co.aurasphere.botmill.fb.model.outcoming.FbBotMillResponse in project fb-botmill by BotMill.

the class FbBotMillBean method validate.

/**
	 * Validates the {@link FbBotMillResponse}.
	 *
	 * @param response
	 *            the response
	 * @return true if the response is valid, false otherwise.
	 */
protected boolean validate(FbBotMillResponse response) {
    // If validations are not enabled, returns true.
    if (!FbBotMillContext.getInstance().isValidationEnabled()) {
        return true;
    }
    boolean valid = true;
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    Validator validator = factory.getValidator();
    Set<ConstraintViolation<FbBotMillResponse>> violations = validator.validate(response);
    for (ConstraintViolation<FbBotMillResponse> v : violations) {
        valid = false;
        logger.error("FbBotMillResponse validation error. Message: [{}] Value: [{}], Class: [{}], Field: [{}]", v.getMessage(), v.getInvalidValue(), v.getRootBean(), v.getPropertyPath());
    }
    if (valid == false) {
        // Sends the constraint violations through the callback.
        List<FbBotMillMonitor> registeredMonitors = FbBotMillContext.getInstance().getRegisteredMonitors();
        for (FbBotMillMonitor monitor : registeredMonitors) {
            monitor.onValidationError(response, violations);
        }
    }
    return valid;
}
Also used : ValidatorFactory(javax.validation.ValidatorFactory) FbBotMillResponse(co.aurasphere.botmill.fb.model.outcoming.FbBotMillResponse) ConstraintViolation(javax.validation.ConstraintViolation) FbBotMillMonitor(co.aurasphere.botmill.fb.support.FbBotMillMonitor) Validator(javax.validation.Validator)

Example 4 with FbBotMillResponse

use of co.aurasphere.botmill.fb.model.outcoming.FbBotMillResponse in project fb-botmill by BotMill.

the class AnnotatedTemplatedBehaviourTest method initialGreeting.

/**
	 * Initial greeting.
	 */
@FbBotMillController(eventType = FbBotMillEventType.MESSAGE_PATTERN, pattern = "(?i:hi)|(?i:hello)|(?i:hey)|(?i:good day)|(?i:home)")
public void initialGreeting(MessageEnvelope envelope) {
    addReply(new AutoReply() {

        @Override
        public FbBotMillResponse createResponse(MessageEnvelope envelope) {
            return ReplyFactory.addTypingAction(TypingAction.TYPING_ON).build(envelope);
        }
    });
    addReply(new AutoReply() {

        @Override
        public FbBotMillResponse createResponse(MessageEnvelope envelope) {
            String greetingMessage = "Hey There! ";
            return ReplyFactory.addTextMessageOnly(greetingMessage).build(envelope);
        }
    });
    addReply(new AutoReply() {

        @Override
        public FbBotMillResponse createResponse(MessageEnvelope envelope) {
            String greetingMessage = "Hey There Again! ";
            return ReplyFactory.addTextMessageOnly(greetingMessage).build(envelope);
        }
    });
    executeReplies();
}
Also used : MessageAutoReply(co.aurasphere.botmill.fb.autoreply.MessageAutoReply) AutoReply(co.aurasphere.botmill.fb.autoreply.AutoReply) FbBotMillResponse(co.aurasphere.botmill.fb.model.outcoming.FbBotMillResponse) MessageEnvelope(co.aurasphere.botmill.fb.model.incoming.MessageEnvelope) FbBotMillController(co.aurasphere.botmill.fb.model.annotation.FbBotMillController)

Example 5 with FbBotMillResponse

use of co.aurasphere.botmill.fb.model.outcoming.FbBotMillResponse in project fb-botmill by BotMill.

the class AttachmentAutoReply method createResponse.

/**
	 * {@inheritDoc} Replies with an attachment.
	 */
@Override
public FbBotMillResponse createResponse(MessageEnvelope envelope) {
    FbBotMillResponse response = null;
    switch(attachmentType) {
        case FILE:
            response = ReplyFactory.addFileAttachment(url).build(envelope);
            break;
        case IMAGE:
            response = ReplyFactory.addImageAttachment(url).build(envelope);
            break;
        case AUDIO:
            response = ReplyFactory.addAudioAttachment(url).build(envelope);
            break;
        case VIDEO:
            response = ReplyFactory.addVideoAttachment(url).build(envelope);
            break;
        default:
            String message = "Illegal attachment of type [ " + attachmentType.name() + " ] for AttachmentAutoReply";
            logger.error(message);
            throw new BotMillIllegalAttachmentException(message);
    }
    return response;
}
Also used : FbBotMillResponse(co.aurasphere.botmill.fb.model.outcoming.FbBotMillResponse) BotMillIllegalAttachmentException(co.aurasphere.botmill.core.internal.exception.BotMillIllegalAttachmentException)

Aggregations

FbBotMillResponse (co.aurasphere.botmill.fb.model.outcoming.FbBotMillResponse)5 AutoReply (co.aurasphere.botmill.fb.autoreply.AutoReply)3 MessageEnvelope (co.aurasphere.botmill.fb.model.incoming.MessageEnvelope)3 MessageAutoReply (co.aurasphere.botmill.fb.autoreply.MessageAutoReply)2 FbBotMillController (co.aurasphere.botmill.fb.model.annotation.FbBotMillController)2 BotMillIllegalAttachmentException (co.aurasphere.botmill.core.internal.exception.BotMillIllegalAttachmentException)1 MessageEvent (co.aurasphere.botmill.fb.event.message.MessageEvent)1 UploadAttachmentResponse (co.aurasphere.botmill.fb.model.api.upload.UploadAttachmentResponse)1 FbBotMillMonitor (co.aurasphere.botmill.fb.support.FbBotMillMonitor)1 ConstraintViolation (javax.validation.ConstraintViolation)1 Validator (javax.validation.Validator)1 ValidatorFactory (javax.validation.ValidatorFactory)1