https://github.com/hawry/messaging
Java API for easy serialization/deserialization of Facebooks Messenger Platform API
https://github.com/hawry/messaging
java java-api-facebook java-api-messenger java-library messenger messenger-api messenger-bot messenger-chatbot messenger-chatbots messenger-platform
Last synced: 7 months ago
JSON representation
Java API for easy serialization/deserialization of Facebooks Messenger Platform API
- Host: GitHub
- URL: https://github.com/hawry/messaging
- Owner: hawry
- License: mit
- Created: 2018-06-27T22:09:12.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-07-11T19:20:10.000Z (over 7 years ago)
- Last Synced: 2025-01-31T13:28:45.667Z (8 months ago)
- Topics: java, java-api-facebook, java-api-messenger, java-library, messenger, messenger-api, messenger-bot, messenger-chatbot, messenger-chatbots, messenger-platform
- Language: Java
- Size: 98.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/Hawry/messaging)
# Messaging
Java API for easy serialization and de-serialization of Facebooks Messenger Platform API. Currently being actively developed.
## Supported FB Graph API versions
## Install
### Gradle
Messaging uses the JitPack service, add the following to your `build.gradle`:
```gradle
repositories {
...
maven {
name "jitpack"
url "https://jitpack.io"
}
...
}dependencies {
implementation 'com.github.hawry:messaging:0.3.0'
}
```Note that you can replace the `0.3.0` with a specific release tag or any other short commit hash.
### Maven
```xml
jitpack.io
https://jitpack.io
```
```xml
com.github.hawry
messaging
0.3.0```
### Other
## Usage
### Usage example
#### Receive a webhook event
```java
import net.hawry.messaging.core.webhook;/* ... */
// the following is linebreaked for brevity and won't compile
String payload = "{
'object':'page',
'entry':[
{
'id':'',
'time':1458692752478,
'messaging':[
{
'sender':{
'id':''
},
'recipient':{
'id':''
},
'message':{
'mid':'mid.1457764197618:41d102a3e1ae206a38',
'text':'hello, world!',
}
}
]
}
]
}";try {
Event event = Event.fromJson(payload);System.out.println(event.getObject()); // results in 'page'
for (Entry entry : event.getEntries()) {
System.out.println(entry.getId()); // results in
Messaging m = entry.getMessaging(); // even though it's an array in the JSON-string, according to the docs there will only ever be a single messaging-object
System.out.println(m.getSender().getId()); //
System.out.println(m.getRecipient().getId()); //
WebhookMessage msg = m.getMessage();
System.out.println(msg.getMessageId()); // $mid.1457764197618:41d102a3e1ae206a38
System.out.println(msg.getText()); // hello, world}
} catch (InvalidJsonException e) {
e.printStackTrace();
}```
### Mark message as 'seen'
```java
import net.hawry.messaging.core.Message;
import net.hawry.messaging.core.MessageBuilder;/* ... */
MessageBuilder builder = new MessageBuilder();
Message msg = builder.setRecipient(new Participant("123"))
.setSenderAction(SenderActionType.MARK_SEEN)
.create();String json;
try {
json = msg.toJson();
} catch (MissingRequiredFieldsException e) {
e.printStackTrace();
}System.out.println(json); /* results in {"recipient": {"id": "123"}, "sender_action": "mark_seen"}
/* ... */
```## License
MIT
## Contributions
Contributions welcome, fork the project and create a pull request.