use of co.aurasphere.botmill.fb.model.incoming.MessageEnvelope in project fb-botmill by BotMill.
the class FbBotMillServlet method doPost.
/**
* Specifies how to handle a POST request. It parses the request as a
* {@link MessengerCallback} object. If the request is not a
* MessengerCallback, then the FbBotMillServlet logs an error and does
* nothing, otherwise it will forward the request to all registered bots in
* order to let them process the callbacks.
*
* @param req
* the req
* @param resp
* the resp
* @throws ServletException
* the servlet exception
* @throws IOException
* Signals that an I/O exception has occurred.
*/
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
logger.trace("POST received!");
MessengerCallback callback = new MessengerCallback();
// Extrapolates and logs the JSON for debugging.
String json = readerToString(req.getReader());
logger.debug("JSON input: " + json);
// Parses the request as a MessengerCallback.
try {
callback = FbBotMillJsonUtils.fromJson(json, MessengerCallback.class);
} catch (Exception e) {
logger.error("Error during MessengerCallback parsing: ", e);
return;
}
// envelope of all the callbacks received to the registered bots.
if (callback != null) {
List<MessengerCallbackEntry> callbackEntries = callback.getEntry();
if (callbackEntries != null) {
for (MessengerCallbackEntry entry : callbackEntries) {
List<MessageEnvelope> envelopes = entry.getMessaging();
if (envelopes != null) {
MessageEnvelope lastEnvelope = envelopes.get(envelopes.size() - 1);
IncomingToOutgoingMessageHandler.getInstance().process(lastEnvelope);
}
}
}
}
// Always set to ok.
resp.setStatus(HttpServletResponse.SC_OK);
}
use of co.aurasphere.botmill.fb.model.incoming.MessageEnvelope 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.incoming.MessageEnvelope 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.incoming.MessageEnvelope in project fb-botmill by BotMill.
the class TestDeserialization method main.
/**
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) {
String json = "{\"sender\":{\"id\":\"USER_ID\"},\"recipient\":{\"id\":\"PAGE_ID\"},\"timestamp\":1458692752478,\"message\":{\"mid\":\"mid.1458696618141:b4ef9d19ec21086067\",\"seq\":51,\"attachments\":[{\"type\":\"image\",\"payload\":{\"url\":\"IMAGE_URL\"}}]}}";
String json2 = "{\"sender\":{\"id\":\"1152902104831488\"},\"recipient\":{\"id\":\"1209810882431614\"},\"timestamp\":1482953812997,\"message\":{\"mid\":\"mid.1482953812997:6c6e910961\",\"seq\":778909,\"attachments\":[{\"title\":\"Alvin's Location\",\"url\":\"https:\\/\\/www.facebook.com\\/l.php?u=https%3A%2F%2Fwww.bing.com%2Fmaps%2Fdefault.aspx%3Fv%3D2%26pc%3DFACEBK%26mid%3D8100%26where1%3D43.899746%252C%2B-79.269825%26FORM%3DFBKPL1%26mkt%3Den-US&h=ATNzUb8qaIa5x61TRftUfE7RxWJE_E-5XeshoVeDOeGprLWnutTFxlENgC7vFhYuD3pB02N6PpzsEgcOiofJShlqT7a-lesSHScIzrLQVGPg-_22e6CETCbNhXeo57KTKsXLQU8&s=1&enc=AZNukLEVHCKFse_g9I7aBKSSgHbB3odYCw_9Do4rhrUXbJvjz_okfOP0gGwjSJ9Cd5PRpkxhT9kiCBrGBbXQCqPejz98NXzD6V6WVIEB4ZaDqA\",\"type\":\"location\",\"payload\":{\"coordinates\":{\"lat\":43.899746,\"long\":-79.269825}}}]}}";
MessageEnvelope envelope = FbBotMillJsonUtils.fromJson(json, MessageEnvelope.class);
Payload payload = envelope.getMessage().getAttachments().get(0).getPayload();
UrlPayload actualPayload = (UrlPayload) payload;
System.out.println(actualPayload.getUrl());
}
use of co.aurasphere.botmill.fb.model.incoming.MessageEnvelope in project fb-botmill by BotMill.
the class AnnotatedTemplateTest method testAnnotatedQuickReplyTemplateBot.
@Test
public void testAnnotatedQuickReplyTemplateBot() {
String json = "{\"sender\":{\"id\":\"1158621824216736\"},\"recipient\":{\"id\":\"1226565047419159\"},\"timestamp\":1490832021661,\"message\":{\"mid\":\"mid.$cAAUPCFn4ymdhTcignVbHH3rzpKd_\",\"seq\":844819,\"text\":\"quick replies\"}}";
MessageEnvelope envelope = FbBotMillJsonUtils.fromJson(json, MessageEnvelope.class);
IncomingToOutgoingMessageHandler.getInstance().process(envelope);
assertNotNull(envelope);
}
Aggregations