项目作者: codedrinker

项目描述 :
A most easily usable Facebook Messenger Platform API
高级语言: Java
项目地址: git://github.com/codedrinker/facebook-messenger.git
创建时间: 2017-01-30T05:40:18Z
项目社区:https://github.com/codedrinker/facebook-messenger

开源协议:Apache License 2.0

下载


facebook-messenger

A most easily usable Facebook Messenger Platform API

Usage

中文接入文档

中文文档

Add the maven dependency

  1. <dependency>
  2. <groupId>com.github.codedrinker</groupId>
  3. <artifactId>facebook-messenger</artifactId>
  4. <version>1.0.0</version>
  5. </dependency>

Start with FMClient instance, get FMClient instance in FMClicent.getInstance().

  1. FMClient fmClient = FMClient.getInstance();

Use with* methods set parameters to FMClient instance.

  1. //new PostBack Handler to receive the postback message from facebook
  2. public class FMPPostbackHandler extends FMMessagePostBackHandler {
  3. @Override
  4. public void handle(FMReceiveMessage.Messaging message) {
  5. log.debug("FMPPostbackHandler handlePostBack, sender -> {}, postback -> {}", message.getSender(), message);
  6. }
  7. }
  1. //get FMClient instance, and set token, secret, handler paramter.
  2. FMClient fmClient = FMClient.getInstance();
  3. FMPPostbackHandler fmpPostbackHandler = new FMPPostbackHandler();
  4. fmClient.withAccessToken("token")
  5. .withAccessSecret("secret")
  6. .withFmMessagePostBackHandler(fmpPostbackHandler);

Use signature method to valid the payload.

  1. String xHubSignature = request.getHeader("X-Hub-Signature");
  2. StringBuilder buffer = new StringBuilder();
  3. BufferedReader reader = request.getReader();
  4. String line;
  5. while ((line = reader.readLine()) != null) {
  6. buffer.append(line);
  7. }
  8. String payload = buffer.toString();
  9. boolean signature = fmClient.signature(payload, xHubSignature);
  10. if(signature){
  11. //do
  12. } else {
  13. //forbid
  14. }

Use dispatch method to dispatch payload message.

  1. fmClient.dispatch(payload);

Road Map

1.0.0

Apache License

Copyright 2017 Chunlei Wang

Licensed under the Apache License, Version 2.0 (the “License”);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Example

https://github.com/codedrinker/facebook-messenger-example