Skip to content

Commit

Permalink
Issue #200 - webhook listener docs added
Browse files Browse the repository at this point in the history
  • Loading branch information
nbartels committed Jun 9, 2020
1 parent a3f6097 commit 8a87bfb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions _data/menu_documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
title: Webhook Types in RestFB
file: documentation/using-webhooks-types.md
href: using-webhooks-types
-
title: Webhook made easy
file: documentation/using-webhooks-listener.md
href: using-webhooks-listener
-
title: Messenger Platform
file: documentation/messenger-overview.md
Expand Down
25 changes: 25 additions & 0 deletions _includes/documentation/using-webhooks-listener.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Webhooks are a great feature, but using them is not that easy. The objects have a complex structure and mostly in development the `changes` or the `MessagingItem` objects are used.
These two object classes are the important objects of every webhook and so we have implemented a helper class that gives developers the opportunity to implement a suitable listener.
The object structure is run through and a callback method is called for each relevant `Value` or` MessagingItem` object.
So that developers can write a clear class, we have prepared an abstract class that should be used as a basis.

As an example, we would like to react to `FeedCommentValue` changes. To do this, we first implement a short class:

{% highlight java %}
class MyFeedCommentListener extends AbstractWebhookChangeListener {
@Override
public void feedCommentValue(FeedCommentValue feedCommentValue) {
// do some stuff with the FeedCommentValue here
}
}
{% endhighlight %}

Then we register the listener and pass a `WebhookObject`. And the listener is already active.

{% highlight java %}
Webhook webhook = new Webhooks();
webhook.registerListener(new MyFeedCommentListener());
webhook.process(webhookObject);
{% endhighlight %}

If you want to react to a MessagingItem instead of the changes, the class must be derived from the `AbstractWebhookMessagingListener`.
2 changes: 1 addition & 1 deletion _includes/head.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>{{ site.title.default }}{% if page.title %} - {{ page.title }}{% endif %}</title>
<title>{{ site.title.default }}{% if page.title %} - {{ page.title }}{% endif %} - Connecting Java and Facebook</title>
<meta name="viewport" content="width=device-width">
<meta name="description" content="{{ site.description }}">
<link rel="alternate" hreflang="x-default" href="{{ page.url | replace:'index.html','' | prepend: site.baseurl | prepend: site.url }}"/>
Expand Down

0 comments on commit 8a87bfb

Please sign in to comment.