-
Notifications
You must be signed in to change notification settings - Fork 24
Unit Testing
FaceBot offers a powerful framework for testing your bot without even deploying it. In order to do that, you can use the FaceBotMockMediator class. Here's an example using jUnit:
@Test
public void test(){
FaceBotMockMediator mediator = new FaceBotMockMediator("12345678912345", MyBehavior.class);
mediator.sendTextMessage("Hello!");
mediator.sendPayload("MyCustomPayload");
}
The FaceBotMockMediator constructor takes as arguments a String which represents your page-scoped Facebook ID and one or more classes (or actual instances) of your FaceBotDefinition.
Notice that the page-scoped Facebook ID is NOT the same as your Facebook ID. At the moment I'm writing this, the only method I know to get your ID is through FaceBot logs. For an explanation on how to enable logging in FaceBot, refer to the 'Logging' section.
If you enable the debug level logging, you should be able to see the JSON sent to Facebook. Here's an example line of log:
16:01:30.478 DEBUG [http-bio-127.6.222.1-8080-exec-2][FaceBotNetworkAwareBean] Request: {"message":{"text":"This is a bot reply to a user message. The field recipient.id contains the user page-scoped ID."},"recipient":{"id":"123456778975"}}
I'm still looking for a proper way of getting the page-scoped ID. If you know how to do that, please contact me or edit this page.
Once you have instantiated your FaceBotMediator, you will have two methods to test it:
- sendMessage(String message), simulates a user that sends a message through Facebook Messenger chat to your bot.
- sendPayload(String payload), simulates a user that triggers an event that sends a payload back (clicking a button, selecting a quick reply...).
FB-BotMill - Copyright (c) 2016 BotMill.io