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);
}
});
}
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);
}
});
}
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;
}
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();
}
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;
}
Aggregations