Facebook Messenger bot object structure for java

Lexi Mize picture Lexi Mize · Apr 28, 2016 · Viewed 9.2k times · Source

Has anyone created an open source project that exposes the facebook messenger bot API in java? (or another language I could convert?)

Essentially an object hierarchy for the stack found in: https://developers.facebook.com/docs/messenger-platform/send-api-reference

I'd rather not just use JsonObjects, etc. nor Maps to extract the incoming JSON chat messages or to build the outgoing structured chat replies. If an open source project for this exists -- I have not found it.

Answer

Aurasphere picture Aurasphere · Oct 18, 2016

Take a look at FaceBot. The goal of FaceBot is making the Facebook's Messenger Platform easier: with FaceBot, you only need less than 5 lines of code to set up your own Messenger bot.

Here's an example:

public class MyFaceBotBehavior extends AbstractFaceBot {

  public void defineBehavior() {
     // Setting my tokens from Facebook (page token and validation token for webhook).
     FaceBotContext.getInstance().setup("myFacebookPageToken", "myFacebookWebhookValidationToken");

     // Defining a bot which will reply with "Hello World!" as soon as I write "Hi"
     addActionFrame(new MessageEvent("Hi"),
          new MessageAutoReply("Hello World!"));
 }
}

If you have questions or need help, feel free to contact me (I'm the developer).