Skip to content

Commit 519875c

Browse files
committed
Adding direct Heroku client
1 parent eead2d9 commit 519875c

File tree

8 files changed

+112
-12
lines changed

8 files changed

+112
-12
lines changed

Diff for: Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: node heroku/index.js

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ These are sample clients for [Facebook's Graph API Webhooks](https://developers.
44

55
1. [Parse](parse)
66
1. [Heroku](heroku)
7+
1. [Hubot](hubot)

Diff for: app.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "Graph API Webhooks Sample",
3+
"repository": "https://github.com/fbsamples/graph-api-webhooks-samples"
4+
}

Diff for: heroku/README.md

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
# Graph API Webhooks Heroku Sample
22

3-
This example is a [Hubot](https://hubot.github.com/) script that messages a chat room when a Facebook Page post is published using Facebook's [Graph API Webhooks](https://developers.facebook.com/docs/graph-api/webhooks/). The message includes a link to the Facebook post. The bot will post another message with the number of likes on the post after a configurable number of minutes.
4-
5-
These instructions assume you have already set up [Hubot on Heroku](https://hubot.github.com/docs/deploying/heroku/).
3+
This is a sample client for [Facebook's Graph API Webhooks](https://developers.facebook.com/docs/graph-api/webhooks/) and [Instagram's Real-time Photo Updates API](https://instagram.com/developer/realtime/), powered by [Node.js on Heroku](https://devcenter.heroku.com/articles/getting-started-with-nodejs).
64

75
## Setup
86

9-
1. Download `graph-api-webhooks.coffee`.
10-
1. Add a line to `hubot-scripts.json` with `graph-api-webhooks`.
11-
1. Create a new [Facebook application](https://developers.facebook.com/apps) and/or register an [Instagram API client](https://instagram.com/developer/clients/manage/).
12-
1. Using `token` as the verify_token, set up your Facebook application's [Graph API Webhooks subscription](https://developers.facebook.com/docs/graph-api/webhooks/#setup) using `https://<your-subdomain>.herokuapp.com/facebook` as the callback URL, and/or your Instagram client's [Real-time Photo Updates subscription](https://instagram.com/developer/realtime/) using your `https://<your-subdomain>.herokuapp.com/instagram` as the callback URL.
13-
1. Set the Heroku configuration values defined at the top of `graph-api-webhooks.coffee` before deploying.
14-
- `FACEBOOK_APP_ACCESS_TOKEN` - [access token](https://developers.facebook.com/docs/facebook-login/access-tokens#apptokens) for your Facebook app
15-
- `REAL_TIME_ROOM` - chat room for Hubot to post in
16-
- `WAIT_MINUTES` - number of minutes to wait before retrieving the number of likes on the post
17-
1. Install the Facebook app on your Facebook Page using the [Page subscribed apps endpoint](https://developers.facebook.com/docs/graph-api/reference/page/subscribed_apps).
7+
### Heroku
8+
1. Deploy with this button: [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)
9+
1. Test your deployment with `curl https://<your-subdomain>.herokuapp.com` - you should see "It works!".
10+
11+
12+
### Facebook
13+
1. Create a new [Facebook application](https://developers.facebook.com/apps).
14+
1. Set up your Facebook application's [Graph API Webhooks subscription](https://developers.facebook.com/docs/graph-api/webhooks/#setup) using `https://<your-subdomain>.herokuapp.com/facebook` as the callback URL and `token` as the verify_token.
15+
16+
### Instagram
17+
1. Register an [Instagram API client](https://instagram.com/developer/clients/manage/).
18+
1. Set up your client's [Real-time Photo Updates subscription](https://instagram.com/developer/realtime/) using your `https://<your-subdomain>.herokuapp.com/instagram` as the callback URL and `token` as the verify_token.

Diff for: heroku/index.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Copyright 2016-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
var bodyParser = require('body-parser');
10+
var express = require('express');
11+
var app = express();
12+
13+
app.set('port', (process.env.PORT || 5000));
14+
app.listen(app.get('port'));
15+
16+
app.use(bodyParser.json());
17+
18+
app.get('/', function(req, res) {
19+
console.log(req);
20+
res.send('It works!');
21+
});
22+
23+
app.get(['/facebook', '/instagram'], function(req, res) {
24+
if (
25+
req.param('hub.mode') == 'subscribe' &&
26+
req.param('hub.verify_token') == 'token'
27+
) {
28+
res.send(req.param('hub.challenge'));
29+
} else {
30+
res.sendStatus(400);
31+
}
32+
});
33+
34+
app.post('/facebook', function(req, res) {
35+
console.log('Facebook request body:');
36+
console.log(req.body);
37+
// Process the Facebook updates here
38+
res.sendStatus(200);
39+
});
40+
41+
app.post('/instagram', function(req, res) {
42+
console.log('Instagram request body:');
43+
console.log(req.body);
44+
// Process the Instagram updates here
45+
res.sendStatus(200);
46+
});
47+
48+
app.listen();

Diff for: hubot/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Graph API Webhooks Hubot Sample
2+
3+
This example is a [Hubot](https://hubot.github.com/) script that messages a chat room when a Facebook Page post is published using Facebook's [Graph API Webhooks](https://developers.facebook.com/docs/graph-api/webhooks/). The message includes a link to the Facebook post. The bot will post another message with the number of likes on the post after a configurable number of minutes.
4+
5+
These instructions assume you have already set up [Hubot on Heroku](https://hubot.github.com/docs/deploying/heroku/) or Hubot on another platform.
6+
7+
## Setup
8+
9+
1. Download `graph-api-webhooks.coffee`.
10+
1. Add a line to `hubot-scripts.json` with `graph-api-webhooks`.
11+
1. Create a new [Facebook application](https://developers.facebook.com/apps) and/or register an [Instagram API client](https://instagram.com/developer/clients/manage/).
12+
1. Using `token` as the verify_token, set up your Facebook application's [Graph API Webhooks subscription](https://developers.facebook.com/docs/graph-api/webhooks/#setup) using `https://<your-subdomain>.herokuapp.com/facebook` as the callback URL, and/or your Instagram client's [Real-time Photo Updates subscription](https://instagram.com/developer/realtime/) using your `https://<your-subdomain>.herokuapp.com/instagram` as the callback URL.
13+
1. Set the Heroku configuration values defined at the top of `graph-api-webhooks.coffee` before deploying.
14+
- `FACEBOOK_APP_ACCESS_TOKEN` - [access token](https://developers.facebook.com/docs/facebook-login/access-tokens#apptokens) for your Facebook app
15+
- `REAL_TIME_ROOM` - chat room for Hubot to post in
16+
- `WAIT_MINUTES` - number of minutes to wait before retrieving the number of likes on the post
17+
1. Install the Facebook app on your Facebook Page using the [Page subscribed apps endpoint](https://developers.facebook.com/docs/graph-api/reference/page/subscribed_apps).
File renamed without changes.

Diff for: package.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "graph-api-webhooks-samples",
3+
"version": "0.1.0",
4+
"description": "Graph API Webhooks Sample",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "node heroku/index.js"
8+
},
9+
"dependencies": {
10+
"body-parser": "~1.15.0",
11+
"express": "~4.13.3"
12+
},
13+
"engines": {
14+
"node": "0.12.7"
15+
},
16+
"repository": {
17+
"type": "git",
18+
"url": "https://github.com/fbsamples/graph-api-webhooks-samples"
19+
},
20+
"keywords": [
21+
"node",
22+
"heroku",
23+
"express",
24+
"graph api"
25+
],
26+
"license": "https://github.com/fbsamples/graph-api-webhooks-samples/blob/master/LICENSE",
27+
"bugs": "https://github.com/fbsamples/graph-api-webhooks-samples/issues"
28+
}

0 commit comments

Comments
 (0)