Facebook Messenger bot object structure for java

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

Essentially a hierarchy of objects for the stack, found at: https://developers.facebook.com/docs/messenger-platform/send-api-reference

I would rather not just use JsonObjects, etc., nor Maps to extract incoming JSON chat messages or to create outgoing structured chat responses. If there is an open source project for this, I have not found it.

+4
source share
3 answers

FaceBot. FaceBot - Facebook Messenger: FaceBot 5 , -.

:

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!"));
 }
}

, ( ).

+4

messenger4j , .

Java Messenger.

API- . , Java- . .

:

String payload = ... // callback request body
String signature = ... // 'X-Hub-Signature' request header

// JDK 8 version
MessengerReceiveClient receiveClient = MessengerPlatform.newReceiveClientBuilder("APP_SECRET", "VERIFICATION_TOKEN")
        .onTextMessageEvent(event ->  System.out.printf("%s: %s", event.getSender().getId(), event.getText()))
        .build();

// JDK 7 version
MessengerReceiveClient receiveClient = MessengerPlatform.newReceiveClientBuilder("APP_SECRET", "VERIFICATION_TOKEN")
        .onTextMessageEvent(new TextMessageEventHandler() {
            @Override
            public void handle(TextMessageEvent event) {
                System.out.printf("%s: %s", event.getSender().getId(), event.getText());
            }
        })
        .build();

receiveClient.processCallbackPayload(payload, signature);

():

MessengerSendClient sendClient = MessengerPlatform.newSendClientBuilder("PAGE_ACCESS_TOKEN").build();
sendClient.sendTextMessage("RECIPIENT_ID", "Hi there, how are you today?");

():

ReceiptTemplate receipt = ReceiptTemplate.newBuilder("Stephane Crozatier", "12345678902", "USD", "Visa 2345")
        .orderUrl("http://petersapparel.parseapp.com/order?order_id=123456")
        .timestamp(1428444852L)
        .addElements()
            .addElement("Classic White T-Shirt", 50F)
                .subtitle("100% Soft and Luxurious Cotton")
                .quantity(2)
                .currency("USD")
                .imageUrl("http://petersapparel.parseapp.com/img/whiteshirt.png")
                .toList()
            .addElement("Classic Gray T-Shirt", 25F)
                .subtitle("100% Soft and Luxurious Cotton")
                .quantity(1)
                .currency("USD")
                .imageUrl("http://petersapparel.parseapp.com/img/grayshirt.png")
                .toList()
            .done()
        .addAddress("1 Hacker Way", "Menlo Park", "94025", "CA", "US").street2("").done()
        .addSummary(56.14F).subtotal(75.00F).shippingCost(4.95F).totalTax(6.19F).done()
        .addAdjustments()
            .addAdjustment()
                .name("New Customer Discount")
                .amount(20.00F)
                .toList()
            .addAdjustment()
                .name("$10 Off Coupon")
                .amount(10.00F)
            .toList()
        .done()
        .build();

sendClient.sendTemplate("RECIPIENT_ID", receipt);

: .

+3

java, JBot, fb , Slack .

+1

All Articles