Search in sources :

Example 6 with MessageEnvelope

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);
}
Also used : MessageEnvelope(co.aurasphere.botmill.fb.model.incoming.MessageEnvelope) Test(org.junit.Test) AnnotatedTemplatedBehaviourTest(co.aurasphere.botmill.fb.test.autoreply.template.AnnotatedTemplatedBehaviourTest)

Example 7 with MessageEnvelope

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);
}
Also used : MessageEnvelope(co.aurasphere.botmill.fb.model.incoming.MessageEnvelope) Test(org.junit.Test) AnnotatedTemplatedBehaviourTest(co.aurasphere.botmill.fb.test.autoreply.template.AnnotatedTemplatedBehaviourTest)

Example 8 with MessageEnvelope

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);
}
Also used : MessageEnvelope(co.aurasphere.botmill.fb.model.incoming.MessageEnvelope) Test(org.junit.Test) AnnotatedTemplatedBehaviourTest(co.aurasphere.botmill.fb.test.autoreply.template.AnnotatedTemplatedBehaviourTest)

Example 9 with MessageEnvelope

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");
}
Also used : MessengerCallback(co.aurasphere.botmill.fb.model.incoming.MessengerCallback) ListTemplatePayload(co.aurasphere.botmill.fb.model.outcoming.payload.template.ListTemplatePayload) Attachment(co.aurasphere.botmill.fb.model.base.Attachment) EchoMessage(co.aurasphere.botmill.fb.model.incoming.callback.EchoMessage) MessageEnvelope(co.aurasphere.botmill.fb.model.incoming.MessageEnvelope) Test(org.junit.Test)

Example 10 with MessageEnvelope

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!");
}
Also used : User(co.aurasphere.botmill.fb.model.base.User) ReceivedMessage(co.aurasphere.botmill.fb.model.incoming.callback.ReceivedMessage) MessageEnvelope(co.aurasphere.botmill.fb.model.incoming.MessageEnvelope)

Aggregations

MessageEnvelope (co.aurasphere.botmill.fb.model.incoming.MessageEnvelope)18 AnnotatedTemplatedBehaviourTest (co.aurasphere.botmill.fb.test.autoreply.template.AnnotatedTemplatedBehaviourTest)8 Test (org.junit.Test)8 AutoReply (co.aurasphere.botmill.fb.autoreply.AutoReply)3 FbBotMillController (co.aurasphere.botmill.fb.model.annotation.FbBotMillController)3 User (co.aurasphere.botmill.fb.model.base.User)3 FbBotMillResponse (co.aurasphere.botmill.fb.model.outcoming.FbBotMillResponse)3 BotDefinition (co.aurasphere.botmill.core.BotDefinition)2 MessageAutoReply (co.aurasphere.botmill.fb.autoreply.MessageAutoReply)2 MessengerCallback (co.aurasphere.botmill.fb.model.incoming.MessengerCallback)2 ReceivedMessage (co.aurasphere.botmill.fb.model.incoming.callback.ReceivedMessage)2 Bot (co.aurasphere.botmill.core.annotation.Bot)1 BotMillEventMismatchException (co.aurasphere.botmill.core.internal.exception.BotMillEventMismatchException)1 FbBotMillEvent (co.aurasphere.botmill.fb.event.FbBotMillEvent)1 MessageEvent (co.aurasphere.botmill.fb.event.message.MessageEvent)1 UploadAttachmentResponse (co.aurasphere.botmill.fb.model.api.upload.UploadAttachmentResponse)1 Attachment (co.aurasphere.botmill.fb.model.base.Attachment)1 Payload (co.aurasphere.botmill.fb.model.base.Payload)1 MessengerCallbackEntry (co.aurasphere.botmill.fb.model.incoming.MessengerCallbackEntry)1 EchoMessage (co.aurasphere.botmill.fb.model.incoming.callback.EchoMessage)1