use of co.aurasphere.botmill.fb.model.incoming.MessageEnvelope in project fb-botmill by BotMill.
the class AnnotatedTemplateTest method testImageBot.
@Test
public void testImageBot() {
String json = "{\"sender\":{\"id\":\"1158621824216736\"},\"recipient\":{\"id\":\"1226565047419159\"},\"timestamp\":1491360469304,\"message\":{\"mid\":\"mid.$cAACFqTvPOHVhbUgZOFbO_0AFXqVh\",\"seq\":854986,\"attachments\":[{\"type\":\"image\",\"payload\":{\"url\":\"https:\\/\\/scontent.xx.fbcdn.net\\/v\\/t34.0-12\\/17742285_136721643528794_1945065811_n.gif?_nc_ad=z-m&oh=97198065e4ede9bd09330764a7bfb62f&oe=58E6A075\"}}]}}";
MessageEnvelope envelope = FbBotMillJsonUtils.fromJson(json, MessageEnvelope.class);
IncomingToOutgoingMessageHandler.getInstance().process(envelope);
assertNotNull(envelope);
}
use of co.aurasphere.botmill.fb.model.incoming.MessageEnvelope in project fb-botmill by BotMill.
the class AnnotatedTemplateTest method testAnnotatedButtonTemplateBot.
@Test
public void testAnnotatedButtonTemplateBot() {
String json = "{\"sender\":{\"id\":\"1158621824216736\"},\"recipient\":{\"id\":\"1226565047419159\"},\"timestamp\":1490832021661,\"message\":{\"mid\":\"mid.$cAAUPCFn4ymdhTcignVbHH3rzpKd_\",\"seq\":844819,\"text\":\"button template\"}}";
MessageEnvelope envelope = FbBotMillJsonUtils.fromJson(json, MessageEnvelope.class);
IncomingToOutgoingMessageHandler.getInstance().process(envelope);
assertNotNull(envelope);
}
use of co.aurasphere.botmill.fb.model.incoming.MessageEnvelope in project fb-botmill by BotMill.
the class AnnotatedTemplateTest method testAnnotatedReceiptTemplateBot.
@Test
public void testAnnotatedReceiptTemplateBot() {
String json = "{\"sender\":{\"id\":\"1158621824216736\"},\"recipient\":{\"id\":\"1226565047419159\"},\"timestamp\":1490832021661,\"message\":{\"mid\":\"mid.$cAAUPCFn4ymdhTcignVbHH3rzpKd_\",\"seq\":844819,\"text\":\"receipt template\"}}";
MessageEnvelope envelope = FbBotMillJsonUtils.fromJson(json, MessageEnvelope.class);
IncomingToOutgoingMessageHandler.getInstance().process(envelope);
assertNotNull(envelope);
}
use of co.aurasphere.botmill.fb.model.incoming.MessageEnvelope in project fb-botmill by BotMill.
the class EchoCallbackTest method testEchoWithListTemplate.
/**
* Tests an {@link EchoMessage} containing a {@link ListTemplatePayload}.
*/
@Test
public void testEchoWithListTemplate() {
// Tests the echo with a List Template.
String echoListTemplatejson = "{\"object\":\"page\",\"entry\":[{\"id\":\"1423903854504468\",\"time\":1483578465379,\"messaging\":[{\"sender\":{\"id\":\"****\"},\"recipient\":{\"id\":\"****\"},\"timestamp\":1483578464765,\"message\":{\"is_echo\":true,\"app_id\":****,\"mid\":\"mid.1483578464765:ed1fe23f35\",\"seq\":785209,\"attachments\":[{\"title\":\"Title1, Title2, Title3, Title4\",\"url\":\"https://www.facebook.com/commerce/update/\",\"type\":\"template\",\"payload\":{\"template_type\":\"list\",\"sharable\":false,\"elements\":[{\"title\":\"Title1\",\"item_url\":\"http://www.alvinjayreyes.com/\",\"image_url\":\"http://blog.domainmonkee.com/wp-content/uploads/2014/05/url.jpg\",\"subtitle\":\"This is a sample sub title for your product\",\"buttons\":[{\"type\":\"postback\",\"title\":\"View\",\"payload\":\"view\"}],\"default_action\":{\"type\":\"web_url\",\"url\":\"http://www.alvinjayreyes.com/\"}},{\"title\":\"Title2\",\"item_url\":\"http://www.alvinjayreyes.com/\",\"image_url\":\"http://blog.domainmonkee.com/wp-content/uploads/2014/05/url.jpg\",\"subtitle\":\"This is a sample sub title for your product\",\"buttons\":[{\"type\":\"postback\",\"title\":\"View\",\"payload\":\"view\"}],\"default_action\":{\"type\":\"web_url\",\"url\":\"http://www.alvinjayreyes.com/\"}},{\"title\":\"Title3\",\"item_url\":\"http://www.alvinjayreyes.com/\",\"image_url\":\"http://blog.domainmonkee.com/wp-content/uploads/2014/05/url.jpg\",\"subtitle\":\"This is a sample sub title for your product\",\"buttons\":[{\"type\":\"postback\",\"title\":\"View\",\"payload\":\"view\"}],\"default_action\":{\"type\":\"web_url\",\"url\":\"http://www.alvinjayreyes.com/\"}},{\"title\":\"Title4\",\"item_url\":\"http://www.alvinjayreyes.com/\",\"image_url\":\"http://blog.domainmonkee.com/wp-content/uploads/2014/05/url.jpg\",\"subtitle\":\"This is a sample sub title for your product\",\"buttons\":[{\"type\":\"postback\",\"title\":\"View\",\"payload\":\"view\"}],\"default_action\":{\"type\":\"web_url\",\"url\":\"http://www.alvinjayreyes.com/\"}}],\"buttons\":[{\"type\":\"postback\",\"title\":\"Just Sample\",\"payload\":\"Yes\"}]}}]}}]}]}";
MessengerCallback callback = FbBotMillJsonUtils.fromJson(echoListTemplatejson, MessengerCallback.class);
MessageEnvelope messageEnvelope = checkCallbackWellFormed(callback);
EchoMessage echoMessage = super.assertInstanceOf(messageEnvelope.getMessage(), EchoMessage.class);
// Checks that individual fields are correctly parsed.
Assert.assertTrue(echoMessage.isEcho());
Assert.assertEquals("****", echoMessage.getAppId());
Assert.assertEquals("mid.1483578464765:ed1fe23f35", echoMessage.getMid());
Assert.assertEquals("785209", echoMessage.getSeq());
super.assertListOfSize(1, echoMessage.getAttachments());
// Checks the attachment.
Attachment attachment = echoMessage.getAttachments().get(0);
Assert.assertEquals("Title1, Title2, Title3, Title4", attachment.getTitle());
Assert.assertEquals("https://www.facebook.com/commerce/update/", attachment.getUrl());
Assert.assertEquals(AttachmentType.TEMPLATE, attachment.getType());
// Checks the payload.
ListTemplatePayload payload = super.assertInstanceOf(attachment.getPayload(), ListTemplatePayload.class);
Assert.assertEquals(PayloadType.LIST, payload.getTemplateType());
super.assertListOfSize(4, payload.getElements());
for (int i = 0; i < 4; i++) {
checkListTemplateElements(payload.getElements().get(i), i + 1);
}
// Checks the buttons.
super.assertListOfSize(1, payload.getButtons());
checkPostbackButtonWellFormed(payload.getButtons().get(0), "Just Sample", "Yes");
}
use of co.aurasphere.botmill.fb.model.incoming.MessageEnvelope in project fb-botmill by BotMill.
the class FbBotMillMockMediator method sendTextMessage.
/**
* Sends a text message to all the registered bots. Used to simulate a user
* typing in chat with your bot.
*
* @param message
* the message to send.
*/
public void sendTextMessage(String message) {
MessageEnvelope envelope = new MessageEnvelope();
ReceivedMessage body = new ReceivedMessage();
body.setText(message);
envelope.setMessage(body);
envelope.setSender(new User(facebookMockId));
System.out.println("Sending message: [" + message + "] as user : [" + facebookMockId + "].");
forward(envelope);
System.out.println("Sent!");
}
Aggregations